Numerical Recipes Forum  

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

Thread Tools Display Modes
Old 03-16-2004, 11:33 AM
bgbg bgbg is offline
Join Date: Mar 2004
Posts: 2
ran2 problems (bug???)

I've copied the ran2 function from
I use time(NULL) as initial seed.
For some reason first eight numbers are totally equal from one run to another. There are some more equal nubers in other places.
I test the program with the following commands (on linux)
$ ./ran2test > one; sleep 1;
$ ./ran2test >two;
$ paste one two | awk -F' ' '{print $1-$2}' | cat -n
These commands generate two different sequences and then compare the corresponding elements.

I've attached a text file that contains the ran2 function, the test program and some outputs.
Can someone comment on this ?
Reply With Quote
Old 03-18-2004, 03:32 PM
Saul Teukolsky Saul Teukolsky is offline
Numerical Recipes Author
Join Date: Jan 2002
Posts: 212
It turns out bgbg forgot to initialize ran2 with a negative seed.
Reply With Quote
Old 03-19-2004, 03:48 PM
bgbg bgbg is offline
Join Date: Mar 2004
Posts: 2

it was a classic RTFM mistake. Sorry.
Reply With Quote

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 04:09 PM.

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