Generating random number inside a paralleled loop (openmp) What is the most fast and safe way of generating random numbers inside a pararelled loop? I did as below but I'm not sure if it is correct or not:

using namespace std;
std::minstd_rand gen(std::random_device{}());
std::uniform_real_distribution&lt;double&gt; unirnd(0, 1);
int main(){
double eta=something;
double x[N];
//initializing x[] 
for (i=0;i&lt;N;i++)
{
double z= unirnd(gen) * eta;
x[i] = some function of x[i] and z
}
}


To compile the code, I use g++ -fopenmp -std=gnu++11 -Wall -Wextra -g code.cpp -o a.out
Generating good random numbers is a hard problem, and generating parallel random numbers is harder. (Consider that you don't want to replicate the same sequence in different threads). You should use a library which provides a parallel random number generator (such as Intel MKL [now free for anyone]). It has an implementation of the generator described in Parallel Random Numbers: As Easy as 1, 2, 3 which may be appropriate.