C++ 获取随机数
#include <iostream>
#include <sys/timeb.h>
#include <windows.h>
using namespace std;
// 获取随机数
int GetRandNum()
{
// 获取毫秒时间;
struct timeb timeSeed;
ftime(&timeSeed);
// 设置随机数种子
srand(int(timeSeed.time * 1000 + timeSeed.millitm)); // milli time
// 获取随机数
unsigned int crand = rand();
return crand % 100;
}
int main()
{
// 循环获取 50个随机数
for (int i=0; i<50; i++)
{
int rand_count = GetRandData();
cout << rand_count << "\t";
if ((i+1)%10==0)
{
cout << endl;
}
Sleep(100);
}
system("pause");
return 0;
}