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; }