On C++, I am using random_device to seed my 64-bit mersenne twister as follows:
random_device rand_dev;
mt19937_64 mersenne_generator(rand_dev());
And then calling the distribution function inside the loop:
double rand_no = uniform_real_distribution<double>(0.0,1.0)(mersenne_generator);
In other words, the standard way of using mt19937_64, as far as I'm aware. I am using this for a Monte Carlo simulation, and so far it has worked quite well.
However, I for future simulations I would like the simulation results to be fully reproducible based on a stored seed. Such that running:
mt19937_64 mersenne_generator(stored_rand_dev);
For the same parameter set and a given stored_rand_dev will result in the same outputs.
My first thought was to store the results of the random_device as some kind of integer or string. However, naive typecasting random_device to a integer does not work, nor does using to_string. I was wondering if there was an alternative method of storing random_device? Preferably in a form that can occupy a single cell in a tsv file.
Alternatively, I thought of using random device to choose an unsigned integer from 0 to INT_MAX and using this as a seed for mt19937. However, I was unsure if this would affect the quality of random numbers generated by mt19937 versus using random_device. Could anyone advise on this as well?
Aucun commentaire:
Enregistrer un commentaire