random
Random engines and distributions.
Easy
std::mt19937 rng{std::random_device{}()};
std::uniform_int_distribution<int> die(1, 6);
int roll = die(rng);
Don't use rand() % n.
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.