📅  最后修改于: 2022-03-11 14:44:50.751000             🧑  作者: Mango
// For pseudo-random number generators and distributions
#include
...
// Use random_device to generate a seed for Mersenne twister engine.
std::random_device rd{};
// Use Mersenne twister engine to generate pseudo-random numbers.
std::mt19937 engine{rd()};
// "Filter" MT engine's output to generate pseudo-random double values,
// **uniformly distributed** on the closed interval [0, 1].
// (Note that the range is [inclusive, inclusive].)
std::uniform_real_distribution dist{0.0, 1.0};
// Generate pseudo-random number.
double x = dist(engine);