title: random numbers and multiple srand calls
body: <p>I'm writing a program that will generate numerous random numbers in loops.  I'm trying to make the numbers somewhat less predictable (not only for security, but to avoid collisions on multiple threads).</p>
  
  <p>I've noticed that many documents recommended calling <code>srand</code> only once in the program.  For example: <a href="https://stackoverflow.com/questions/2449456/random-numbers-in-c">Random numbers in C</a>, the selected answer is "As a general rule, only call srand() once in your program".</p>
  
  <p>But why?  Why would it be so bad to do something like this:</p>
  
  <pre><code>int THIS_THREAD_SEED;
  int randomness() {
      ++THIS_THREAD_SEED;
      int i;
      for(i=0 i&lt;1000; i++) {
          unsigned n = rand_r(&amp;THIS_THREAD_SEED) / RAND_MAX;
          /* do something with n */
      }
      return 0;
  }
  
  int do_something() {
      int i;
      for(i=0; i&lt;1000; i++) {
          randomness();
      }
  }
  </code></pre>
  
  <p>As such, the seed changes once per function call, not once per program.  This way, no matter how many threads are running, no two threads will every have the same random number list... Right?</p>
  
  <p><strong>UPDATE</strong>
  Assume I either have a unique seed for each thread, or mutex on a global SEED to prevent race conditions.</p>