random number generator

Karl Heuer karl at haddock.ISC.COM
Fri Feb 19 03:41:29 AEST 1988


Followups to sci.math; this has nothing to do with C anymore.

>[A good approximation to a Gaussian distribution can be obtained by
>generating about 12 independent random numbers uniformly from [0,1), adding
>them together, and dividing by 12.]

Actually, the reason for using 12 of them (not "about 12") is that you don't
need to rescale.  The variance of the uniform distribution is 1/12, so adding
12 of them gives you a distribution with variance 1.  If you subtract 6, you
then have a good approximation of a standard Gaussian.

I happen to prefer the polar-coordinate version, because it's mathematically
exact, requires only one call to the uniform RNG per result, and is faster (or
so I've been told).

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list