swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WARNING on Numerical Recipes in C


From: Theodore C. Belding
Subject: Re: WARNING on Numerical Recipes in C
Date: Sat, 10 Jul 1999 02:20:33 -0400 (EDT)

The first edition of NR is known to be buggy, especially the RNGs. The
second is much less so. (If you're using the first edition, toss it and
get the second.) The only bug I've run into in about 5 years of using the
RNGs from the second edition is a bug in the seeding of ran3, pointed out
to me by Terry Jones, which is listed on their bug web page at
http://www.nr.com (unless it's fixed by now in their source code). I've
implemented several of Knuth's [1] tests for RNGs, and the NR RNGs pass
them. George Marsaglia said that NR's ran2 was "a good generator" [2].
Perhaps your friends mistyped the routines from the book. It's hard to
tell exactly what the problem could be, since you don't give any details.

There's a lot of folklore going around about bugs in the second edition of
NR. It's good to report such bugs, and it's always good to be suspicious
of the code that you use. Test your random number generators, by all
means! But it would be nice if these vague rumors would be substantiated
with actual code that reproduces the bug. Strangely, I've never seen
anyone exhibit such an example, except for Terry Jones. Nor have I seen
any documentation of their RNGs failing a statistical test of randomness
that they should have passed.

I don't have any connection with NR besides using their code, but I don't
think propagating vague and unsubstantiated rumors is a good way to
conduct scholarship.

In any case, the second edition of Numerical Recipes in C is a very good
reference for algorithms and the basic theory of random number generators,
whether or not you use their source code.  
-Ted

[1] Knuth, Donald E. (1998). The Art of Computer Programming.  Volume
2: Seminumerical Algorithms. Third edition. Section 3.3,
pp. 41-80. Reading, MA: Addison-Wesley.  

[2] Marsaglia, George, and Arif Zaman. (1994). Some portable
very-long-period random nubmer generators. Computers in Physics 8(1):
117-121.

--
Ted Belding                              address@hidden 
University of Michigan Center for the Study of Complex Systems
Homepage: http://www-personal.umich.edu/~streak/
PGP key:  http://www-personal.umich.edu/~streak/pgp-key.html

On Fri, 9 Jul 1999, donalson wrote:

> I have come upon two instances where there were major errors caused by using
> Numerical Recipies.  The first occurance was when a post-doc in mathmatical
> ecology
> was getting strange results from from the same simulation but using different
> loop structures.
> After a fair amount of discussion I suggested that he try another generator,
> even something
> as simple as RAND() to see what happened.  Because the generator he was using
> was from
> such a respected source, he was very resistent but eventually agreed to try
> it.  The
> problem went away.
> 
> Last month an almost idential situation happened, this time with a
> physics/mathmatical ecology
> doctoral student.  Given that there was no apparent reason for the simualtion
> behavior, I suggested
> she try, (for test purposes only) RAND().  One again, the anomalies
> disappeared.
> 
> There are obviously potentially serious problems with some of the RNG
> algorithms in
> Numerical Recipies, I don't know where they stem from nor which generators
> were
> involved.  I do know that both individuals involved are very competent
> programmers
> and mathematicians, so the likelyhood of programming error on their part is
> very low.
> 
> Moral of the story, run a good set of tests (Swen has provided references for
> a bunch
> of them in the swarm docs) before you depend on a generator from this
> reference.
> 
> D3
> 
> --
> *********************************************************************
> * Doug Donalson                 Office: (805) 893-2962
> * Ecology, Evolution,           Home:   (805) 961-4447
> * and Marine Biology            email address@hidden
> * UC Santa Barbara
> * Santa Barbara Ca. 93106
> *********************************************************************
> *
> *   The most exciting phrase to hear in science, the one that
> *   heralds new discoveries, is not "EUREKA" (I have found it) but
> *   "That's funny ...?"
> *
> *       Isaac Asimov
> *
> *********************************************************************
> 
> 
> 
>                   ==================================
>    Swarm-Support is for discussion of the technical details of the day
>    to day usage of Swarm.  For list administration needs (esp.
>    [un]subscribing), please send a message to <address@hidden>
>    with "help" in the body of the message.
> 



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]