#include <random>
int RandomNum(const int& Lowerlimit, const int& UpperLimit)
{
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dis(Lowerlimit, UpperLimit);
int num = dis(gen);
return num;
}
使用模板实现浮点数:
std::uniform_real_distribution<double> dis(Lowerlimit, UpperLimit);