在C++生成随机数,不是单单一个
rand();
就能解决的,如果你试过,那么你会发现,每次运行数字都一样,这是要加一个时间种子
他就是臭名鼎鼎大名鼎鼎的——
srand((unsigned int)time(NULL));
下面是一个栗子例子:
#include<bits/stdc++.h>
#include<Windows.h>
using namespace std;
int main(){
srand((unsigned int)time(NULL));
int x=rand();
cout<<x;
return 0;
}
本例子每次运行输出结果均不相同(请使用Dev C++)
如有问题,请大胆提出