1.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
//第一种方法,自己输出设置随机数种子
//设置随机数种子
unsigned seed;
cin >> seed;
srand(seed);
int a = rand();
int b = rand();
int c = rand();
cout << a <<' ' << b <<' ' << c;
return 0;
}
//输入相同数字时产生的随机数相同#include <iostream>
2.
#include <cstdlib>
#include<ctime>
using namespace std;
int main()
{
//第二种方法,设置时间随机种子,包含头文件<ctime>
//设置随机数种子
unsigned seed;
seed = time(0);
srand(seed);
int a = rand();
int b = rand();
int c = rand();
cout << a <<' ' << b <<' ' << c;
return 0;
}
3.范围随机数
a = rand() % end+start;