comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: random number trap
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: random number trap [message #4985 is a reply to message #4983] Tue, 29 August 1995 00:00 Go to previous message
scott is currently offline  scott
Messages: 17
Registered: January 1994
Junior Member
Peter Webb writes
> A warning about the random number generator in IDL/PV-Wave (not a bug,
> per se, but something to watch out for).
>
> As the documentation states, if the seed value given to randomu is
> undefined, it is derived from the system time. The time only changes
> once per second, however. So if you repeatedly call a procedure that
> calls randomu, the return will be the same if the calls occur within a
> second of each other, but will be different if they are in different
> seconds.
>
> This can lead to random numbers being a *lot* more structured than you
> expect. I had naively expected that the seed value would change each
> microsecond, so this behavior came as a bit of a surprise.
>
> The solution is to place the seed variable in a common block so that it
> is preserved from call to call, and then each returned sequence will
> truly be random.
>
> Peter
>
> --------------------------------
> Peter Webb, HP Labs Medical Dept
> E-Mail: peter_webb@hpl.hp.com
> Phone: (415) 813-3756

Actually, the problem goes much deeper than the granularity of the system
time, and hinges on what you mean by "random." Many scientific users
expect a "random" variable to have a Gaussian distribution, which no
"random number generator" in any language is likely to provide.

For an excellent discussion of this problem, as well as nice, simple
solutions, see W. H. Press et al., 1992: Numerical Recipes, Cambridge
University Press, Chapter 7 (Random Numbers).

--
A. Scott Denning scott@abyss.Atmos.ColoState.edu
Dept. of Atmospheric Science Phone (970)491-2134
Colorado State University Fax1 (970)491-8428
Fort Collins, CO 80523-1371 Fax2 (970)491-8449
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: MESSAGE question
Next Topic: DROPLIST bug ?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Dec 02 15:47:51 PST 2025

Total time taken to generate the page: 1.76203 seconds