In all examples shown in the previous recipe, we used an std::mt19937 engine to produce pseudo-random numbers. Though the Mersenne twister is slower than the other engines, it can produce the longest sequences of non-repeating numbers and with the best spectral characteristics. However, initializing the engine in the manner shown in the previous recipe will not have this effect. With a careful analysis (that is beyond the purpose of this recipe or this book), it can be shown that the engine has a bias toward producing some values repeatedly and omitting others, thus generating numbers not in a uniform distribution, but rather in a binomial or Poisson distribution. The problem is that the internal state of mt19937 has 624 32-bit integers, and in the examples from the previous recipe we have only initialized one of them.
When working with the pseudo-random number library, remember the following rule of thumb (shown in the information box):
The pseudo-random number library provides a class for this particular purpose, called std::seed_seq. This is a generator that can be seeded with any number of 32-bit integers and produces a requested number of integers evenly distributed in the 32-bit space.
In the preceding code from the How to do it... section, we defined an array called seed_data with a number of 32-bit integers equal to the internal state of the mt19937 generator; that is 624 integers. Then, we initialized the array with random numbers produced by an std::random_device. The array was later used to seed an std::seed_seq, which in turn was used to seed the mt19937 generator.