Search This Blog

Google Analytics

Tuesday, April 06, 2010

Calculate a Random Number from a Normal Distribution

Visual Basic 6.0 / VBA code to calculate random number from a normal distribution using Box-Muller Transformation method.


Function BoxMullerTransformation() As Double
    'Make use of BoxMullerTransformation to calculate a Random Number from a Normal Distribution
    'http://mathworld.wolfram.com/Box-MullerTransformation.html
    Randomize
    BoxMullerTransformation = Sqr(-2 * Log(Rnd)) * Sin(2 * PI() * Rnd)
End Function

Mathematics can be interesting :)

No comments:

Post a Comment

Do provide your constructive comment. I appreciate that.

Popular Posts