Random numbers: Normal Distribution II

We present a simple macro that returns a random number with normal distribution.


Function RandNormal As Double

randomize

Dim PI As Double

PI = 3.1412

RandNormal = sqr(-2 * log(1-rnd())) * cos(rnd() * 2 * PI)

End Function
To verify the correctness of our macro, we invoke this function many times and calculate the average and standard deviation of the resulting random data. For normally distribution, we are loking for an average close to 0.0 and a standard deviation close to 1.0

normal2.jpg

Leave a Reply