For a course I am trying to implement a parallel Monte Carlo simulation. One of the requirements of the project is that the exact results should be repeatable. In my current design I have a job 'queue' implemented implemented by an instance of std::default_random_engine
and a set of workers. A worker takes a 'job' and uses it as a seed for its own rng (also an instance of std::default_random_engine
) and runs the simulation using that instance.
While the results are indeed repeatable, it does leave me with some questions:
- Does using a rng to seed a pool of rngs create some kind of bias? If it depends on which rng is used (and it probably does), which one should i use?
- Is this design all right or are there alternatives?
--edit-- After having looked into it a bit further I notice the following: std::default_random_engine
uses a simple linear congruential generator. Its state is simply its previous value. This means the results of my pool of rngs are exactly the same, but shifted by one. The mersenne twister (which has a larger internal state) doesn't show this behaviour:
#include <iostream>
#include <random>
int main(int argc, char** argv)
{
std::default_random_engine e1(1);
std::default_random_engine e2(e1());
std::cout << e1() << ",\n" << e2() << '\n';
std::mt19937_64 e3(1);
std::mt19937_64 e4(e1());
std::cout << e3() << ",\n" << e4() << '\n';
}
which outputs:
282475249,
282475249
2469588189546311528,
5601807455758261240