I m 试图在0到1之间随机生成真实数字,使用Boost C++uniform_01
功能和Mersenne Twister算法。 这是我的法典:
double random01(mt19937 & generator)
{
uniform_01<mt19937> dist(generator);
return dist();
}
int main()
{
mt19937 generator(time(0));
for (int i = 0; i < 10; i++) {
cout << random01(generator) << endl;
}
return 0;
}
However, this code generates the same random number on every iteration of the loop. I know this is a repeat of this question, but that question was closed for being ambiguous, so I rephrased it.