[DGD] Damage Weapons and Stuff (Math and Code)

White, Ben ben.white at dsto.defence.gov.au
Mon Jun 2 08:13:21 CEST 2003


You can generate gaussian distributed random numbers
with the following (assuming randf() generates a
uniformly distributed number between 0 and 1):

  mag = sqrt (-2.0 * log10 (randf() + 1E-9));
  phase = 2.0 * pi * randf();

  x = mag * cos (phase);
  y = mag * sin (phase);

Both x and y will be normally distributed (mean 0,
std. dev 1).

Another version that some people use is to add up
a whole bunch of uniformly distributed numbers.  It
works out very nicely if you use 12 numbers.  Eg:

  sum = 0.0;
  for (i = 0; i < 12; i++) sum += randf();
  x = sum - 6.0;

Hope this helps.
Ben White.

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list