numpy performance and random numbers

Lie Ryan lie.1296 at gmail.com
Sat Dec 19 19:46:37 EST 2009


On 12/20/2009 8:58 AM, sturlamolden wrote:
> On 19 Des, 21:26, Lie Ryan<lie.1... at gmail.com>  wrote:
>
>> you can just start two PRNG at two distinct states
>
> No. You have to know for certain that the outputs don't overlap.

Not necessarily, you only need to be certain that the two streams don't 
overlap in any reasonable amount of time. For that purpose, you can use 
a PRNG that have extremely high period like Mersenne Twister and puts 
the generators to very distant states.

> If you pick two random states (using any PRNG), you need error-
> checking that states are always unique, i.e. that each PRNG never
> reaches the starting state of the other(s). If I had to do this, I
> would e.g. hash the state to a 32 bit integer. You can deal with
> errors by jumping to a different state or simply aborting the
> simulation. The problem is that the book-keeping will be costly
> compared to the work involved in generating a single pseudorandom
> deviate. So while we can construct a parallel PRNG this way, it will
> likely run slower than one unique PRNG.

You will need some logic to ensure that your generator's states are 
distant enough, but that won't incur any generation overhead. Of course 
this relies on the very large period of the PRNG algorithm.



More information about the Python-list mailing list