Flip a biased coin
This pattern is licensed under the CC0 Public Domain Dedication.
Generate a random boolean value according to a bernoulli 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.
On line 7, we create a
representing a bernoulli distribution with a success probability of
0.25. This can be thought of as a biased coin that will land on
heads only a quarter of the time.
Finally, we generate a random number from the random engine,
distributed according to the bernoulli distribution (line 9).
This gives us a boolean value that will be