[DGD] Damage Weapons and Stuff (Math and Code)
White, Ben
ben.white at dsto.defence.gov.au
Tue Jun 3 04:12:45 CEST 2003
From: Ben Chambers [mailto:bjchamb at bellsouth.net]
>
> http://www.taygeta.com/random/gaussian.html
>
> The code found there follows:
> float x1, x2, w, y1, y2;
>
> do {
> x1 = 2.0 * ranf() - 1.0;
> x2 = 2.0 * ranf() - 1.0;
> w = x1 * x1 + x2 * x2;
> } while ( w >= 1.0 );
>
> w = sqrt( (-2.0 * ln( w ) ) / w );
> y1 = x1 * w;
> y2 = x2 * w;
>
> As the websites explains, ranf is a function to return a
> random number in
> the range [0, 1]. The problem is the number of calls that
> occur to ranf.
> There is the potential that a lot of calls would be made.
> How would DGD
> handle this? How fast is the random generation function in DGD?
>
The area of the square in which the number is being uniformly
generated is 4 (2 * 2). The area of the circle in which the
numbers are chosen is 3.14159... (pi * r**2). So you have a
better than 75% chance of getting your number first pop.
This does the same thing as one version I posted before, only
with the looping instead of a cos/sin...
Ben.
_________________________________________________________________
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list