title: What's a good way to seed a random number generator to work with forking?
body: <p>Suppose I have a function <code>generateId</code> to generate random 64-bit integers. If I write <code>generateId</code> like this</p>
  
  <pre><code>uint64_t generateId() {
    static thread_local std::mt19937_64 rng{std::random_device{}()};
    return rng();
  }
  </code></pre>
  
  <p>Then <code>rng</code> won't get reseeded after a fork. Running</p>
  
  <pre><code>int main() {
    std::cout &lt;&lt; generateId() &lt;&lt; "\n";
    if (fork() == 0) {
      std::cout &lt;&lt; "child: " &lt;&lt; generateId() &lt;&lt; "\n";
    } else {
      std::cout &lt;&lt; "parent: " &lt;&lt; generateId() &lt;&lt; "\n";
    }
    return 0;
  }
  </code></pre>
  
  <p>Will print the same number for child and parent.</p>
  
  <p>Is there a way I can write <code>generateId</code> so that it reseeds for new processes but still remains performant.</p>