参考链接
- https://www.bilibili.com/video/BV1et411b73Z?p=32
这里是根据系统时间产生随机数种子,所以需要添加头文件“ctime”。
#include <iostream>
using namespace std;
// 系统时间头文件
#include <ctime>
int main()
{
// 添加随机数种子
srand((unsigned int)time(NULL));
// 生成随机数
int num = rand() % 100 + 1;
cout << "随机数:" << num << endl;
system("pause");
return 0;
}