RE: Separate threads of random numbers
- Posted by Rod Jackson <rodjackson_x at hotmail.com> Apr 07, 2002
- 387 views
Looks good, but will this avoid any algorithmic pitfalls? I.e., one thread in 100 finds a quirk in the psuedorandom algorithm and continually brings up the same number over and over? Stuff like that can be a headache.... Could you not rewrite the M. Twister to use multiple independent "sets" of random numbers? For example, instead of simply one sequence holding the state of the twister, have several that hold the state of several twisters. I think it would do the trick, and wouldn't be a lot of work... I'd try it myself, but don't think I'll have the time. Then again, this may suit your needs anyway. Rod Andy Serpa wrote: > Thanks, Pete. > > Sometimes I am so stupid. The more obvious something is the less chance > > I have to notice it. I wrote something almost identical except I didn't > set the seed EVERY time I got a value as I should, but only when I was > switching threads. When I realized that didn't work, my brain > apparently threw out the whole concept... > > > petelomax at blueyonder.co.uk wrote: > > On Sun, 7 Apr 2002 14:10:25 +0000, Andy Serpa > > <renegade at earthling.net> wrote: > > > > How about doing this: > > init(): > > set_rand(12345) > > seed[1]=rand(1073741823) -- use max range for thread seeds > > seed[2]=rand(1073741823) > > seed[3]=rand(1073741823) > > > > & > > function get_next_rand(integer thread, integer limit) > > integer result > > set_rand(seed[thread]) > > result=rand(limit) > > seed[thread]=rand(1073741823) > > return result