View Full Version : Random Number Generation

beardgh

08-07-2009, 12:58 AM

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

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.

beardgh

08-08-2009, 01: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? :)

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.

beardgh

08-08-2009, 09:33 PM

i get it!

Powered by vBulletin® Version 4.2.3 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.