|
|
-[You can approximate a normal distribution of numbers...]-
...but this is an inefficient method. The standard method is the Box-Muller
transform, given here in C.
float v1,v2,rsq,fac;
do
{
v1=rand()*2.0-1.0; v2=rand()*2.0-1.0;
rsq=v1*v1+v2*v2;
} while (rsq>=1.0 || rsq==0.0)
fac=sqrt(-2.0*log(rsq)/rsq);
This generates two independent normal deviates (v1*fac) and (v2*fac) (with
zero mean and unit variance). The "rand()" function here generates uniform
deviates between 0 and 1.
-[...and dividing the result by n]-
Actually, with this method you need to divide by sqrt(n) if you want to keep
the variance independent of n.
-Chris
Post a reply to this message
|
|