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

Home » Public Forums » archive » random numbers with gamma distribution
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 Numbers [message #81814 is a reply to message #13427] Thu, 25 October 2012 08:06 Go to previous messageGo to previous message
John O'Neill is currently offline  John O'Neill
Messages: 2
Registered: October 2012
Junior Member
On Thursday, October 25, 2012 10:37:58 AM UTC-4, David wrote:
> Yngvar Larsen writes:
>
>
>
>>
>
>> On Wednesday, 24 October 2012 23:38:34 UTC+2, John O'Neill wrote:
>
>>> Hello Everyone,
>
>>>
>
>>> I am trying to create a set of random numbers using an Inverse Gaussian Distribution (Wald distribution) but randomu doesn't seem able to do this. Is there anything more general then randomu, or something where I can define what function I want to use to create random numbers?
>
>>
>
>>
>
>> Google and Wikipedia are your friends.
>
>>
>
>> http://en.wikipedia.org/wiki/Inverse_Gaussian_distribution#G enerating_random_variates_from_an_inverse-Gaussian_distribut ion
>
>>
>
>> IDL> N = 100
>
>> IDL> mu = 1d0 & lambda = 1d0
>
>> IDL> nu = randomn(seed, N)
>
>> IDL> z = randomu(seed, N)
>
>> IDL> igvariates = dblarr(N)
>
>> IDL> y = nu^2
>
>> IDL> x = mu + mu^2*y/(2*lambda) - mu/2/lambda*sqrt(4*mu*lambda*y + mu^2*y^2)
>
>> IDL> ind = where(z le mu/(mu+x), complement=cind)
>
>> IDL> igvariates[ind] = x[ind]
>
>> IDL> igvariates[cind] = mu^2/x[cind]
>
>>
>
>> Include checking for empty index arrays IND and/or CIND if you use IDL version < 8.0.
>
>
>
> This code is easy enough to implement that I just wrote
>
> a function, cgRandomWald to do it this morning. You can
>
> find it here:
>
>
>
> http://www.idlcoyote.com/programs/cgrandomwald.pro
>
>
>
> It works very much like the other RandomX functions in IDL.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")

Thank you very much David, Yngvar, and Craig for your help. This is exactly what I was looking for.

John
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: VALUE_LOCATE and NaNs
Next Topic: Re: VALUE_LOCATE and NaNs

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

Current Time: Wed Oct 08 20:14:11 PDT 2025

Total time taken to generate the page: 0.00288 seconds