Dealing with generators
Given any generator object g
, you can perform the following operations on it:
g()
: This scrambles the internal state of the generator and yields its next output.g.min()
: This tells you the smallest possible output ofg()
(typically0
).g.max()
: This tells you the largest possible output ofg()
. That is, the range of possible outputs ofg()
isg.min()
tog.max()
inclusive.g.discard(n)
: This effectively makesn
calls tog()
and discards the results. In a good library implementation, you'll pay for scrambling the generator's internal staten
times, but save any cost associated with computing the next outputs from the state.
Truly random bits with std::random_device
The std::random_device
is a generator. Its interface is incredibly simple; it's not even a class template, just a plain old class. Once you've constructed an instance of std::random_device
using its default constructor, you can use its overloaded call operator to fetch values of type unsigned int
that are uniformly...