title: Java Configuring random number generators in multi-threaded environment
body: <p>I have an application which uses pseudo-random numbers. While I'm testing the application, I want reproducibility, which I arrange by using a seed for the random number generator.  Currently, the RNG is declared inside the class that uses it as a static variable: <code>private static Random rng = new Random(seed)</code>. I have a few questions.</p>
  
  <ol>
  <li>Given that I want to seed the RNG for reproducibility, does it make sense to declare the variable <code>static</code>?</li>
  <li>I may need to add more different classes which need random numbers. Should I move the RNG to a separate class so I can still use one seed for the whole application? If so, should I use a <code>static Random</code> or a singleton object?</li>
  <li>What happens if I decide to use random numbers in multiple threads? It seems that if I use a strategy like 2., I might still lose predictability, as I can't say for sure the order in which the threads are going to access the RNG. The RNG will still generate the same, predictable sequence of random numbers, but from one run of the program to another, the thread which grabs the first (or nth) random number in the sequence may differ.</li>
  <li>What this indicates to me is that each thread needs its own RNG in order for results to be reproducible across all runs. Does that mean that each thread needs its own seed? If so, would that guarantee reproducibility, or is there something else I need to do to eliminate the randomness that may be introduced by having multiple threads?</li>
  <li>Is there a way to generate seeds from a single number which minimizes the correlation between the different RNGs?</li>
  </ol>
  
  <p>In other words, if thread 0 has <code>Random thread0RNG = new Random(seed)</code> and thread 1 has <code>Random thread1RNG = new Random(seed)</code>, I would only need one seed, but the random numbers in each thread would be highly correlated. I could have two seeds, but then I couldn't associate a run of the program with a single number, passed on the command line, say. Would it be possible and appropriate to say <code>seed0 = someFunction(seed,0)</code> and <code>seed1 = someFunction(seed,1)</code>?</p>