Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   how to generate a random number in c++ ? (http://www.go4expert.com/forums/generate-random-cpp-t8068/)

b.t.e 2Jan2008 02:11

how to generate a random number in c++ ?
 
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++ ?

pradeep 2Jan2008 12:39

Re: how to generate a random number in c++ ?
 
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;
}



All times are GMT +5.5. The time now is 14:54.