两次运行程序产生的随机数序列相同
2.用srand()
两次运行程序产生的随机数则不同
示例程序:
#include<iostream> #include<cstdio> #include<cstdlib> // rand()、srand() #include<ctime> // time() using namespace std; int main(){ int i; srand(time(NULL)); // 不加此句的话,两次运行产生的随机数序列相同 for(i=0;i<10;i++){ printf("%d ",rand()%100); } return 0; }