/**************************************************************** Copyright (C) : University of Michigan Project: ENG101/200 - Class example File: rand2.cpp Purpose: An example of the rand() function Compiler: g++ Programmer: Alex Bielajew Revision Date: 10/02/12 ****************************************************************/ /* Remarks: The sequence is seeded by the time function, making every start seem different. Good for programming games! */ //File: rand2.cpp #include #include #include // Need this for the rand() and srand() functions #include // Need this for the time() function using namespace std; int main(void) { cout << "\n\nRAND_MAX = " << RAND_MAX << "\n\n"; // NEW STUFF //////////////////////////////////////////// srand(static_cast(time(NULL))); // Seed the random number generator // // END OF NEW STUFF ///////////////////////////////////// cout << "The first 10 random numbers are...\n"; for(int i = 1; i <= 10; i = i + 1) cout << "Random number " << setw(2) << i << " = " << rand() // Random int between 0 and RAND_MAX inclusive << "\n"; int epoch = static_cast(time(NULL)); cout << "\n\n Number of seconds since the Epoch = " << epoch << "\n\n"; return 0; }