我一直在寻找下面代码补丁的确切 Win 实现。我不是一个伟大的程序员,我的代码最初是在 UNix 中,但我必须尽可能少地修改它以用于 Win。我从一些谷歌搜索中了解到,主要问题是“gettimeofday”,它没有 Win 等价物。但是,我希望尽可能保留相同的程序结构。
struct timeval tv;
time_t curtime;
gettimeofday(&tv, NULL); // ???
curtime = tv.tv_usec;
srand(tv.tv_usec); //time(&curtime)
最佳答案
如果您需要随机种子作为亚秒级数字,请执行以下操作:
#ifdef WIN32
::srand( GetTickCount() );
#else
//your existing code
#endif
关于c++ - 为 Windows 提供带有时间函数的 srand(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12390900/