Solving problems with <random>
There are two core concepts provided by the <random>
header--the generator and the distribution. A generator (a class modeling the UniformRandomBitGenerator
concept) encapsulates the internal state of a PRNG into a C++ object, and provides a next output member function in the form of the function-call operator, operator()(void)
. A distribution (a class modeling RandomNumberDistribution
) is a kind of filter you can place over the output of a generator so that instead of getting uniformly distributed random bits, as you do from rand()
, you get actual data values distributed according to a specified mathematical distribution and constrained to a specific range, such as rand() % n
, but more mathematically appropriate and vastly more flexible.
The <random>
header contains a total of seven generator types and twenty distribution types. Most of them are templates taking lots of parameters. The majority of these generators are more historically interesting...