Cpp - Write program to generate random numbers between 1 and 100

Requirements

Write a C++ program that reads an integer between 0 and 65535 from the keyboard and uses it to seed a random number generator.

Then output 20 random numbers between 1 and 100 on screen.

Hint

To seed a random number

srand( seed);    // Seeds the random 

Demo

#include <stdlib.h>   // Prototypes of srand() and rand() 
#include <iostream> 
#include <iomanip> 
using namespace std; 

int main() /*ww  w. j  av  a 2s.co  m*/
{ 
    unsigned int  i, seed; 

    cout << "\nPlease type an integer between " 
              "0 and 65535: "; 

    cin >> seed;     // Reads an integer. 
    srand( seed);    // Seeds the random 
                         // number generator. 

    cout << "\n\n            " 
              "******   RANDOM NUMBERS   ******\n\n"; 

    for( i = 1 ; i <= 20 ; ++i) 
       cout << setw(20) << i << ". random number = " 
              << setw(3)  << (rand() % 100 + 1) << endl; 

    return 0; 
}

Result

Related Exercise