Best way to seed N independent random number generators from 1 value In my program I need to run N separate threads each with their own RNG which is used to sample a large dataset. I need to be able to seed this entire process with a single value so I can reproduce results.
Is it sufficient to simply sequentially increase the seed for each index?
Currently I use numpy's RandomState which uses a Mersenne Twister pseudo-random number generator.
Snippet of code below:
# If a random number generator seed exists
if self.random_generator_seed:
    # Create a new random number generator for this instance based on its
    # own index
    self.random_generator_seed += instance_index
    self.random_number_generator = RandomState(self.random_generator_seed)

Essentially I start off with a user-inputted seed (if it exists) and for each instance / thread I sequentially add the index (0 to N-1) of the instance running. I don't know if this is good practice or if there's a better way of doing this.
 A: A solution that is used in parallel processing is to use your random generator $\Phi(u)$, where $u$ is your seed, by $N$-batches:


*

*generate $\Phi(u),\Phi^N(u),\Phi^{2*N}(u),...$

*generate $\Phi^2(u),\Phi^{1+N}(u),\Phi^{1+2*N}(u),...$

*...

*generate $\Phi^{N-1}(u),\Phi^{N-1+N}(u),\Phi^{N-1+2*N}(u),...$


where $\Phi^n(u)=\Phi(\Phi^{n-1}(u))$. This way you use a single seed and your sequences are all uniform and independent.
A: There is now a Python package called RandomGen that has methods to achieve this.
It supports independent streams created from a single seed, as well as a jumping protocol for older random number generators such as MT19937.
A: It's not great practice, certainly. For example, consider what happens when you do two runs with root seeds of 12345 and 12346. Each run will have N-1 streams in common.
Mersenne Twister implementations (including numpy.random and random) typically use a different PRNG to expand the integer seed into the large state vector (624 32-bit integers) that MT uses; this is the array from RandomState.get_state(). A good way to do what you want is to run that PRNG, seeded with your input integer once, and get N*624 32-bit integers from it. Split that stream up into N state vectors and use RandomState.set_state() to explicitly initialize each RandomState instance. You may have to consult the C sources of numpy.random or _random from the standard library to get that PRNG (they are the same). I'm not sure if anyone has implemented a standalone version of that PRNG for Python.
A: Some people claim that there are correlations in the random numbers generated by sequential seeds. https://stackoverflow.com/questions/10900852/near-seeds-in-random-number-generation-may-give-similar-random-numbers I'm not sure how true that is.
If you are worried about it, why not use a single random number generator to choose the seeds for all of the other generators?
