我理解time(0)常用于为随机数生成器提供种子,只有当程序每秒运行超过一次时才会成为问题。我想知道在生成随机数时还有哪些更好的种子可供考虑。我了解到Windows上的GetTickCount、timeGetTime和QueryPerformanceCounter。这些是否足以满足几乎所有操作的需求,或者是否有更好的种子选项?
这里是使用boost库的快速代码示例:
#include <iostream>
#include <boost/random.hpp>
using namespace std;
using namespace boost;
int main()
{
mt19937 randGen(42);
uniform_int<> range(0,100);
variate_generator<mt19937&, uniform_int<> > GetRand(randGen, range);
for (int i = 0; i < 30; ++i)
cout << GetRand() << endl;
}