On Friday 03 March 2006 12:55, Vincent Snijders wrote: > Jonas Maebe wrote: > > On 3 mrt 2006, at 13:42, Vinzent Hoefler wrote: > >>> BTW, I never would have guessed that the random number generator > >>> would have used threadvars. I would have thought, that on app > >>> start you would set one randseed and then call random from all > >>> threads. > >> > >> Considering that the state array for the Mersenne Twister is an > >> unprotected global variable, calling random from different threads > >> looks like a bad idea to me. > >> > >> I mean, it surely gives you sort of random values, but ... > > > > That's why its state (and indeed not just randseed) should be > > threadvars. > > Or use some locking mechanism. That would be slower, but would safe > some memory.
I'd suggest both. :) Objectify the whole Mersenne Twister into a single "class", so that each thread can have it's own PRNG if necessary and provide a single global, but locked instance of it for the System.Random subroutines. Vinzent. _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal