PDA

View Full Version : Solved: Normal distribution



troelsi
06-19-2009, 01:57 AM
Hello

I know that I can draw a random number from a uniform distribution using the following code:


dim number as long
dim maxval as long
dim minval as long
maxval = 20
minval = 10
randomize

Number = Int((MaxVal - MinVal + 1) * Rnd + MinVal)


However, I would like to draw a random number from a normal distribution, where I have specified the mean and the standard deviation.
How do I do that? Is it possible to use the data analysis tool via VBA. That is write a VBA code that returns a random number from a given normal distribution - perhaps using the data analysis tool.

Your help is appreciated.

Thank you
Regards Troels

p45cal
06-19-2009, 06:44 AM
I think...:
on a sheet the formula:
=NORMINV(rand(),mean,standard_dev)
In VBA:Number = Application.WorksheetFunction.NormInv(Rnd(), 0.55, 0.2) where .55 is the mean and .2 is the standard deviation.

troelsi
06-19-2009, 06:55 AM
Great thanks a lot