[fpc-devel] Random thread-safe

thaddy at thaddy.com thaddy at thaddy.com
Thu Jan 28 15:18:01 CET 2016


Then wouldn't it be possible to make PRNG's  plugable. The Mersenne 
twister is still good as it is but definitely not suitable for every and 
any case. Marsialigla's might be a better choice nowadays.
And the seeding can nowadays often been done from reading hardware 
random, like on the Raspberry Pi.
e.g. 
http://scruss.com/blog/2013/06/07/well-that-was-unexpected-the-raspberry-pis-hardware-random-number-generator/

But that is not an exclusive.

Thaddy

On 28-Jan-16 1:30 PM, Jonas Maebe wrote:
>
> Ondrej Pokorny wrote on Thu, 28 Jan 2016:
>
>> Regarding: http://bugs.freepascal.org/view.php?id=29526 (because I 
>> cannot answer on closed issues).
>>
>>>> Also: the entire state of the random number generator consists of 
>>>> regular global variables, so it is not safe to use it from multiple 
>>>> threads in parallel.
>>
>> Would it make sense to you to make random thread-safe? E.g. with the 
>> use of "threadvar" instead of "var" for the global variables in 
>> question?
>
> No. The Mersenne twister has a lot of state (about 2KB). Duplicating 
> this for every thread, along with associated slowdown, is not worth 
> it. It's better to use a class that encapsulates the state of a random 
> number generator and then instantiate this class for every thread.
>
>
> Jonas
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel





More information about the fpc-devel mailing list