title: Generating the same random numbers with threads in OMP
body: <p>I am attempting to multithread some code with OMP. Currently my sequentially version using rand() to generate a set of random numbers with a consistent seed so that they return the same results when run each time. I want to parallelise my code but rand() is not thread safe. Can someone please show me how i would go about using a random number generator that works on threads so i can produce the same data set upon each test similar to that of using a seed with rand(). My code im parallelising is as follows:</p>
  
  <pre><code>    long linkCnt;
      long j;
      long t;
      srand(randInit);
  
      linkCnt=0; //Keep track of # of outgoing edges
   #pragma omp parallel for schedule(runtime) private(t)
      for(j = 0; j &lt; G-&gt;N; j++)
      {
  
          if(i == j){
              t = NO_CONN;
          } else {
              t = (rand() % ((MAX_EDGE_WEIGTH-1) * 2)+1); //50% of having no connection
              if(t &gt; MAX_EDGE_WEIGTH){
                  //t = INF; //Like no connection
                  t = NO_CONN; //Like no connection
              } else {
                  linkCnt++;
                  G-&gt;visited[j] = VISITED; //Do this to find isolated nods that have no incomming edge
              }
          }
  
          G-&gt;node[i][j] = t;
      }
  </code></pre>