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

Home » Public Forums » archive » Generate Same Sequence of Random Numbers in IDL and C
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: Generate Same Sequence of Random Numbers in IDL and C [message #89063 is a reply to message #89061] Mon, 21 July 2014 10:16 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 7/21/14, 10:11 AM, sweiss1993@gmail.com wrote:
> I am in the process of developing a C version of a program originally
> written in IDL. The programs generate arrays with random number
> generators. I use gsl_rng_uniform and gsl_ran_poisson in the C
> version, and both random number generators use the gsl_rng_mt19937
> algorithm. From attempting to read GDL's source code, I noticed GDL
> happens to use the same functions.
>
> I would like to compare the two versions of the program by running
> them with the same fixed sequence of random numbers. The rng parts of
> the programs are in a loop, so a new array is generated with each
> iteration. I would like a different set of random numbers for each
> iteration. So, each iteration has a different set of generated
> numbers, but the i-th iteration in the programs should match each
> other.
>
> I could not figure out exactly how GDL sets the seed by reading the
> source code. Would someone be so kind as to show me how to seed the
> rng functions in IDL and C such that the above conditions are met?
> Thanks!
>

In IDL, you specify the seed when calling the random number generator
function, i.e.,

IDL> r = randomu(seed, 1000)

generates 1000 uniformly distributed random numbers. If "seed" is
undefined, it is created from the system clock. I haven't used GSL
random numbers, but it looks like this is how to set the seed for them:

void gsl_rng_set(const gsl_rng *r, unsigned long int seed);

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: rebin vs congrid
Next Topic: IDL and C inter-language communication / call_external()

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

Current Time: Wed Oct 08 17:03:04 PDT 2025

Total time taken to generate the page: 0.00431 seconds