Re: [OpenSTA-devel] Re: When is Random not random?
Brought to you by:
dansut
|
From: Mark E. <ma...@bo...> - 2006-01-06 22:27:50
|
Wickersham, Peter wrote: > 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. <snip> > <initialize A with seed> > GENERATE A => a2 > GENERATE A => a3 > <initialize B with seed> > GENERATE B => b2 > GENERATE B => b3 > GENERATE A => b4 Yes, but we're calling srand(A1),rand(),srand(a2),rand(),srand(a3)... So the 'initialize with seed' is occuring before each call to rand, which should reset the seed before each call. However if another thread called srand() before the first thread rand() had occured I can see the problem you are describing which is why I wondered whether just making the srand(),rand() pair atomic (with a mutex) would solve the issue. As rand() would always be called after a reset with srand() using the same seed this should give the same sequence. Or should it? I haven't written anything like this for a few years now so I could be way off the mark:-) On an earlier note, I can't see anything really wrong with having a class like you suggested earlier I'm just wondering what I've missed here. Mark |