这种方法可以获取cpu周期时间,精确到微秒
__declspec (naked) unsigned __int64 GetCpuCycle(void)
{
_asm
{
rdtsc
ret
}
}
//返回 2 到 n-2的随机数,n>4
int uniform(int n) {
unsigned __int64 iCpuCycle = GetCpuCycle();
unsigned srnd = (unsigned)iCpuCycle;
srand(srnd);
return rand() % (n - 1 - 1) + 1;
}