Normal distribution random number generator -- WANTED
Brian Adkins
adkins at iguana.cis.ohio-state.edu
Mon Dec 3 06:13:19 AEST 1990
>I am looking for C source code to generate normal distribution
>random numbers. I want to be able to generate random numbers
>in the range of 0 - N (N could be equal to 9999, 99999 or 999999) that
>have normal distribution with mean, say, u and standard deviation s.
I'm not sure if this is exactly what you want, but the Box-Muller method
takes a pair of independent uniform variables ("regular random numbers")
and creates a pair of standard normal variables:
z1 = sqrt(-ln(u2)) * cos(2*PI*u1)
z2 = sqrt(-ln(u2)) * sin(2*PI*u1)
where the angle is expressed in radians. You probably can convert from
standard normal variables to the specific case, but for completeness:
x1 = u + s * z1, x2 = u + s * z2 where u is mean, s is std. dev.
this method is almost universally preferred over solving for r = F(z)
most of this info is from "Probability & Statistics for Engineers" Miller...
More information about the Comp.lang.c
mailing list