2
votes

I'm using boost::random::mt19937 generator and I need to print it's seed for debug purposes (in order to reproduce my test) How can I get the seed?

2

2 Answers

1
votes

Use C++11 features.

std::random_device rd;
unsigned long seed = rd();
std::cout << "seed = " << seed << std::endl;

std::mt19937 engine(seed);
0
votes

Rather than trying to extract what you think of as the seed from mt19937, it's easier set the seed explicitly in both runs for reproducibility. See boost's random_demo.cpp, about 20 lines into the main, for an example of setting the seed. The comment points out that using std::time(0) can inadvertently lead to correlated results from two generators if they are seeded in rapid succession based on time. In your case you actually want identical streams, so you want to set the seed to an explicit value such as 54321 rather than using std::time(0). Identical seeding produces identical output from the generator.