title: How to use multi-threaded deterministic PRNG
body: <p>I use TBB to multithread a part of my application.<br />
  The following code was logically responsible for a non-deterministic behavior:</p>
  <pre class="lang-cpp prettyprint-override"><code>    std::mt19937 engine;
      std::uniform_real_distribution&lt;double&gt; distribution(-1., 1.);
  
      double x[N];
  
      tbb::parallel_for(0, N, [&amp;](int i)
      {
          // ... complicated stuff done in this loop
          x[i] = distribution(engine);
      });
  </code></pre>
  <p>I changed the code to use one PRNG per thread, using TBB TLS, and seed the PRNG using the loop index.<br />
  It seems to work but looks weird to me. Is it a common practice?</p>
  <pre class="lang-cpp prettyprint-override"><code>    tbb::enumerable_thread_specific&lt;std::mt19937&gt; engine;
      std::uniform_real_distribution&lt;double&gt; distribution(-1., 1.);
  
      double x[N];
  
      tbb::parallel_for(0, N, [&amp;](int i)
      {
          // ... complicated stuff done in this loop
          engine.local().seed(i);
          x[i] = distribution(engine.local());
      });
  </code></pre>