RE: [OpenSTA-devel] Re: When is Random not random?
Brought to you by:
dansut
|
From: Wickersham, P. <Pet...@di...> - 2006-01-06 22:00:39
|
The issue as I see it is the following. Let's say we have defined two SCRIPT variables as REPEATABLE RANDOM. A and B with 2 different seeds A1 and B1 Now, lets say that if you called srand(A1), you would see the following sequence of numbers from rand(). a2, a3, a4, a5, a6.=20 Now, let's say that you called srand(B1) and would normally see the following sequence of numbers on successive calls to rand(): b2, b3, b4, b5 First off, srand() will reset the seed for all calls to rand() for all threads in the process. So, a sequence like below would occur <initialize A with seed> GENERATE A =3D> a2 <initialize B with seed> GENERATE B =3D> b2 GENERATE A =3D> b3 GENERATE B =3D> b4 OR <initialize A with seed> GENERATE A =3D> a2 GENERATE A =3D> a3 <initialize B with seed> GENERATE B =3D> b2 GENERATE B =3D> b3 GENERATE A =3D> b4 You can see how the actual sequences for A and B could often not repeat just depending on when one or the other was called. I would imagine that you would want to always be able to count the sequence of values generated for A and for B to be the same across multiple runs. I would like to always see A =3D> a2, a3, a4, a5 and B = =3D> b2, b3, b4, b5=20 Now, some *nix systems have a rand_r() which is meant to allow a process to have multiple sequences seeded at different starting points. But, I don't see this in Windows. -peter PS. Looking at the current code, I am guessing that they had this constant calling of srand() in order to deal with this issue. However, the result of rand() is not usually the next seed in the sequence within the actual system call. So, this workaround doesn't work very well. -----Original Message----- From: ope...@li... [mailto:ope...@li...] On Behalf Of Mark Elam Sent: Friday, January 06, 2006 1:14 PM To: ope...@li... Subject: Re: [OpenSTA-devel] Re: When is Random not random? Wickersham, Peter wrote: >=20 > In fact, there already is an issue with this code for REPEATABLE RANDOM > and that is the fact that we are using rand() in the first place. This > is a global function and the seed is a global, as well. So, if you want > more than one REPEATABLE RANDOM sequence, this won't work. I see what you mean, but if the two lines srand (_cur_seed); _cur_seed =3D rand(); were an atomic operation, wouldn't that take care of the problem as far=20 as repeatable random is concerned? Then the #define VOREPRAND could be checked for in _options as to=20 whether repeatable or otherwise (no srand() call) should be used. Or have I missed something obvious? Mark ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick _______________________________________________ OpenSTA-devel mailing list Ope...@li... https://lists.sourceforge.net/lists/listinfo/opensta-devel |