Numerical Recipes Forum  

Go Back   Numerical Recipes Forum > Obsolete Editions Forum > Methods: Chapters 7, 8, and 20

Reply
 
Thread Tools Display Modes
  #1  
Old 03-27-2011, 03:21 AM
Pergerine Pergerine is offline
Registered User
 
Join Date: Mar 2011
Posts: 1
Question random number generators (ran2)

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?
Reply With Quote
  #2  
Old 03-27-2011, 10:33 AM
davekw7x davekw7x is offline
Registered User
 
Join Date: Jan 2008
Posts: 453
Quote:
Originally Posted by Pergerine View Post
hi
hi

Quote:
Originally Posted by Pergerine
using ran2
What version/language of Numerical Recipes? C? C++? Fortran 77? Fortran 90? What?

Quote:
Originally Posted by Pergerine
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++:
Code:
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:
Code:
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
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 02:29 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.