srand+rand() combination

#include <iostream>
#include <cstdlib> /* include to allow rand() to be used */
#include<ctime>/*just used in function: time(NULL)*/
using namespace std;
int main()
{
 int x; /* variable to hold our random integer */
 srand(time(NULL));//system's time, in seconds,if not, the value will not change
 x = rand();
 cout << "x = " << x << endl;
 x = rand();
 cout << "x = " << x << endl;
 return 0;
} 

 

posted on 2020-01-30 15:29  鸣动我心  阅读(130)  评论(0编辑  收藏  举报