0
votes

I want to write a function which will be repeatedly called by other functions many times. Inside this function it is supposed to generate a lot of random numbers and this part will be treated in parallel. If only for one run, the seed can be chosen differently for each thread, so that the random numbers will be uncorrelated. However, if this function will be called the 2nd time, it seems that the random numbers will repeat unless the seed will be again changed during the later calls.

So my question is, is there a good way to generate the random numbers or reset the seed so that the random numbers generated by repeated calls to this function and also by different threads are really random?

I need to do this in openMP. Is it possible to store the state of the generator for each thread separately after each call of the function, so that when the next time the function is called, the random number generator start from the last state and continue to generate uncorrelated numbers?

Thank you.

1
why do you need one per thread, why not share the same generator?AndersK

1 Answers

0
votes

First use strong random number generators like MT. To solve your threading problem make one generator guarded by a mutex that will generate seeds for each thread. Then on each thread use a different generator.
The key is to initialize the minimum number of times you need, for that you will probably need a program global for the seed generator and thread local storage for each thread's generator.