4 Digit Random number generation in C++

There are 9000 four-digit numbers, right? Starting from 1000 till 9999. rand() will return a random number from 0 to rand() % 10000.

Source code :

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

Output :

7865 //Random output will be generated.

Algorithm :

  1. Include math,stdio Header files.
  2. Include the standard Library.
  3. randomizes the seat
  4. prints a random positive integer

Output :


                

Comments :