how to generate a random number in c++ ?

b.t.e's Avatar
Newbie Member
A supermarket wants to test how well their store will function with different number of cashiers serving customers. Write a program that simulates that situation using queues. First, your program should ask how many cashiers will be serving customers. You should make sure that the number entered is between 1 and 5. For each simulated minute you should generate a random number of buyers (between 0 and 3), each buyer takes from 2 to 6 minutes to be served (generate the number of service minutes randomly). Customers are served on a first-come first serve basis. A customer will stay with a cashier until the time required has elapsed, then the cashier can serve the next customer. The simulation ends when no cashiers are busy and no people enter the store.

how to generate a random number in c++ ?
0
pradeep's Avatar, Join Date: Apr 2005
Team Leader
Code: CPP
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int main()
{
    //  Declare variable to hold seconds on clock.
    time_t seconds;
    //Get value from system clock and place in seconds variable.
    time(&seconds);
    //  Convert seconds to a unsigned integer.
    srand((unsigned int) seconds);
    // Output random values.
    cout<< rand() << endl;
    cout<< rand() << endl;
    cout<< rand() << endl;
    return 0;
}