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 #89072 is a reply to message #89071] Tue, 22 July 2014 11:07 Go to previous messageGo to previous message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 7/22/14, 10:21 AM, sweiss1993@gmail.com wrote:
> Hi Mike,
>
> Thanks for the reply! I seeded the way you described, and there is
> still a difference in the random number output for each program. To
> be specific, I seeded both with a constant integer of 4357 (default
> seed for GSL's RNG). I also made sure the seed was not reinitialized
> with every loop iteration. Both programs now have a constant output
> every time the program runs. However, the outputs from the programs
> do not match each other. On closer inspection, I noticed that the
> first random numbers match, but after the next iteration, they are
> not the same.
>
> Since both programs use the same number generator and start with the
> same seed, I am guessing there must be a difference in how GDL
> changes the seed with each call. So, do you or anyone happen to know
> how exactly IDL/GDL changes the seed for a constant seed input? I
> have read the documentation, and attempted to read the GDL C++ source
> code, but neither have been much help in this regard.
>
> - Sam
>

I get the same values:

IDL> mg_gsl_rng_test
% Compiled module: MG_GSL_RNG_TEST.
% Loaded DLM: MG_GSL.
0.12696983
0.51491326
0.96671784
0.89812542
0.26047601
0.70582012
0.89723652
0.77882970
0.37674972
0.93162251
0.126970 0.514913 0.966718 0.898125 0.260476
0.705820 0.897237 0.778830 0.376750 0.931623

Here is the source code for the test:

pro mg_gsl_rng_test
compile_opt strictarr

n = 10L
original_seed = 123456ULL
seed = original_seed

mg_gsl_rng_env_setup
t = mg_gsl_rng_mt19937()
r = mg_gsl_rng_alloc(t)
mg_gsl_rng_set, r, seed

for i = 0L, n - 1L do begin
print, mg_gsl_rng_uniform(r)
endfor

seed = original_seed
print, randomu(seed, n)
end

I tested generating the values one at a time in IDL as well and it is
still the same.

The bindings to call the GSL RNG functions, i.e., mg_gsl_rng_env_setup,
mg_gsl_rng_mt19937, mg_gsl_rng_alloc, mg_gsl_rng_set, and
mg_gsl_rng_uniform are in my library:

http://github.com/mgalloy/mglib

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 19:02:10 PDT 2025

Total time taken to generate the page: 0.00428 seconds