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

Home » Public Forums » archive » 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 #5062 is a reply to message #4986] Wed, 27 September 1995 00:00 Go to previous messageGo to previous message
Adam Shane is currently offline  Adam Shane
Messages: 4
Registered: September 1995
Junior Member
scott@abyss.ATMOS.ColoState.Edu (Scott Denning) wrote:
>
> 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

In IDL there are two routines, RANDOMU and RANDOMN. The former gives
a set of random numbers of UNIFORM distribution over the interval
[0,1) (assuming you don't keep changing the random number seed as
stated above). The latter will give a NORMAL or GAUSSIAN distribution
that you say you "expect." A simple but informative example was
supplied in the IDL documentation for version 3.6.

Adam Shane
Arete Associates
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: determining postition on image?
Next Topic: Display into non-IDL apps/widgets?

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

Current Time: Sun Oct 12 17:23:26 PDT 2025

Total time taken to generate the page: 1.52124 seconds