random number generators (ran2)


Pergerine
03-27-2011, 03:21 AM
hi
im using ran2 as my RNG. im initializing my "seed" as any arbitrary negative value and then running a loop to get 10 random numbers.

i did not change the value of "seed" after the initializing. my problem is that even though the book says the random numbers should be generated between 0.0 and 1.0 im getting the values to be of the order 10^9.

Furthermore while these numbers are random they cease to be random after the 5th iteration of the loop and im getting a constant value of "-419434".

Can anyone tell me whats going on?:confused:

davekw7x
03-27-2011, 10:33 AM
hihi

using ran2
What version/language of Numerical Recipes? C? C++? Fortran 77? Fortran 90? What?

Can anyone tell me whats going on
Well, it's always possible that your Numerical Recipes code library is corrupted or that your compiler doesn't work properly or that your CPU is bad, but my guess would be you wrote a buggy program. (It happens, even to the best of us. Really.)

Anyhow...

How the heck could anyone guess "what's going on" without seeing your code?

Here's the output I get from Version 2 C++:

Seed = -123456
x = 5.147067e-01
x = 7.798369e-01
x = 2.298345e-01
x = 1.264292e-02
x = 7.142276e-01
x = 6.548146e-01
x = 7.834399e-01
x = 6.729629e-01
x = 4.629217e-01
x = 9.073786e-01
x = 4.164615e-01
x = 8.205473e-01
x = 3.420125e-01
x = 3.256488e-01
x = 1.143800e-02
x = 4.128037e-02
x = 7.887734e-01
x = 3.997021e-01
x = 6.184547e-01
x = 6.316700e-01

After 20 calls to ran2: (xmin,xmax) = (1.143800e-02, 9.073786e-01)


Another run:

Seed = -7654321
x = 1.215040e-01
.
. (18 other values here)
.
x = 2.656290e-01

After 20 calls to ran2: (xmin,xmax) = (9.409017e-04, 9.837023e-01)



Want to see my code? Well, I'll show you mine if you show me yours.


Regards,

Dave