There are 9000 four-digit numbers, right? Starting from 1000 till 9999. rand() will return a random number from 0 to rand() % 10000.
#include <math.h> #include <time.h> #include <stdlib.h> #include <iostream> using namespace std; int main(){ srand(time(NULL)); //randomizes the seat cout << rand() % 10000; //prints a random positive integer; }
7865 //Random output will be generated.
Comments :