Roll a die
This pattern is licensed under the CC0 Public Domain Dedication.
Generate a random integer according to a uniform distribution.
std::random_device on line 5
provides a source of uniform non-deterministic random numbers
(where such a source is available). We use this to seed the
Mersenne Twister random number engine,
line 6. Consider other random number
for different properties.
Finally, we generate a random number from the random engine, distributed according to the uniform integer distribution (line 9). This gives us a random integer from 1 to 6, as though we had rolled a 6-sided die.
To generate further random numbers, simply call