/* Test Random Number Generation (TestRand.cpp) */ #include #include // for rand(), srand() #include // for time() using namespace std; int main() { // rand() generate a random number in [0, RAND_MAX] cout << "RAND_MAX is " << RAND_MAX << endl; // 32767 // Generate 10 pseudo-random numbers between 0 and 99 // without seeding the generator. // You will get the same sequence, every time you run this program for (int i = 0; i < 10; ++i) { cout << rand() % 100 << " "; // need header } cout << endl; // Seed the random number generator with current time srand(time(0)); // need and header // Generate 10 pseudo-random numbers // You will get different sequence on different run, // because the current time is different for (int i = 0; i < 10; ++i) { cout << rand() % 100 << " "; // need header } cout << endl; }