Re: random musings [message #53124 is a reply to message #53121] |
Mon, 19 March 2007 21:41   |
Christopher Thom
Messages: 66 Registered: October 2006
|
Member |
|
|
Quoth Wayne Landsman:
> On Mar 19, 4:30 pm, Christopher Thom <c...@oddjob.uchicago.edu> wrote:
>> Hi all,
>>
>> this morning I started writing some monte carlo code, in which I'm
>> generating random arrays, and scaling/shifting them to fit the (gaussian)
>> distribution parameters I need. One thing is not clear in the online help:
>> Which random function is "better"? Should I be using randomn() or
>> randomu()?
>
> I believe these functions are identical. In the ancient days, IDL had
> two types of randomn number generators: RANDOMU, for a uniform
> distribution, and RANDOMN for a normal distribution. When addition
> distributions (e.g. binomial, Poisson, Gamma) were added (in V5.0 I
> believe), RSI chose against adding additional RANDOM* functions, and
> instead made all the distributions available from either RANDOMU or
> RANDOMN.
Hmmmm. If this is true, then the documentation is definitely in need of an
update. Randomn() supposedly uses the "box muller method", while randomu()
uses one from an ACM paper that is cited, with a "bays durham shuffle
added", giving something "similar to ran1()" from NR in C section 7.1.
If they are the same thing, it is certainly not clear from the docs. :-(
OTOH, the interfaces seem very similar...they all provide the same flags
(/gamma, /normal etc), which certainly points towards a common algorithm.
Oh. I just did the obvious thing -- tried both with the same seed:
IDL> x=randomn(180479L, 5,/normal)
IDL> y=randomu(180479L, 5,/normal)
IDL> print,x,y
2.01146 -1.55186 -0.0893551 -0.627972 -0.780082
2.01146 -1.55186 -0.0893551 -0.627972 -0.780082
Surely different algorithms would return different randomness for the same
seed.
Problem solved...
cheers
chris
|
|
|