我有一个函数,我试图生成 18 到 5 之间的随机数
int randomAge() {
int random;
std::random_device rd;
static std::default_random_engine generator(rd()); //produce a static random engine
std::normal_distribution<double> distribution(18, 52); //random age between 18 and 52
random = distribution(generator);
return random;
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到负数和大于 52 的偶数。如何解决此问题,使其生成 18 到 52 之间的数字?