random number generator

Joseph Reger joseph at chromo.ucsc.edu
Thu Feb 18 03:40:43 AEST 1988


In article <225800004 at uxe.cso.uiuc.edu> mcdonald at uxe.cso.uiuc.edu writes:
>
>>Simplistic, but this works:
>>Generate about 12 random numbers (assuming 0.0 <= i <1.0)
>
>       ADD THEM TOGETHER
>
>>and divide by 12.  This is sufficiently close to gaussian distribution
>>for most purposes.  The more numbers you generate before you do the
>>division, the closer you will get to purely gaussian distribution.


Devide by 12??

This method uses the central limit theorem and gives nearly
gaussian (normal) random numbers if the number of uniform
random numbers to be summed up is sufficiently large:
   Take N uniform random deviates on (0,1): u(1), u(2),...,u(N).
Then g = sqrt(12/N) * ( (u(1)+u(2)+...+u(N)) - N/2 )
yields a (nearly) normal variable with mean 0 and variance 1.
N=12 seems to be sufficiently large for most purposes and
avoids computing the sqrt() factor.
(So do not devide by 12, subtract 6!). 
g' = M + D * g gives a normal random number with mean M and
standard deviation D.



More information about the Comp.lang.c mailing list