View Full Version : Random Number Generation

08-06-2009, 11:58 PM
hello ,veryone!:)
I have a problem with number generator of IMSL 5.0 for C#.
How can I find random number for normal distribution other than N(0,1) , for example N(29,5.2)? Which function should I use and how?
Thanks in advance
eagerly Regards

08-07-2009, 04:47 AM
You can use Random.NextNormal() (http://www.vni.com/products/imsl/cSharp/v501/api/Imsl.Stat.Random.NextNormal.html) or Random.NextNormalAR() (http://www.vni.com/products/imsl/cSharp/v501/api/Imsl.Stat.Random.NextNormalAR.html) to get a random number that fits N(0, 1). To fit this to N(m, s) first multiply the output by s then add m.

N(m, s) = s * N(0, 1) + m.

08-08-2009, 12:00 AM
:)i have another question:
int nObservations = 1000;
Imsl.Stat.Random r = new Imsl.Stat.Random(123457);
for (int i = 0; i < nObservations; i++)
double rn = r.NextNormal();
when the code run,why the variable rn has Negative phenomena? :)

08-08-2009, 05:01 AM
The Random.NextNormal() will give you a random number that falls into the normal distribution with mean=0 and std.dev=1, so about half of the values should be negative.

08-08-2009, 08:33 PM
i get it!