- 使用随机数种子
#include <bits/stdc++.h>
using namespace std;
int main() {
strand(unsigned(time(NULL)));
cout << rand() << endl;
cout << rand() << endl;
}
- 注意
- 先获取随机数种子
- rand()返回值是0到2^15
- 头文件
<cstdlib>
#include <bits/stdc++.h>
using namespace std;
int main() {
strand(unsigned(time(NULL)));
cout << rand() << endl;
cout << rand() << endl;
}
<cstdlib>