I have some code which looks a bit like this:
std::random_device rd;
#pragma omp parallel
{
std::mt19937 gen(rd());
#pragma omp for
for(int i=0; i < N; i++)
{
/* Do stuff with random numbers from gen() */
}
}
I have a few questions:
- Is
std::random_device
thread safe? i.e. Is it going to do something unhelpful when several threads call it at once? - Is this generally a good idea? Should I be worried about overlapping random number streams?
- Is there a better way to achieve what I want (independent random number streams in each thread - I'm not too worried about reproducibility at the moment)?
In case it make any difference to the workings of std::random_device
I'm primarily running on Windows, though I would like the code to work equally well on Linux and OSX as well.