# include # include # include using namespace std; int main ( ) { int i; unsigned int seed; cout << "\n"; cout << "1: No call to srand( ).\n"; cout << "Here are the first five default random values:\n"; cout << "\n"; for ( i = 1; i <= 5; i++ ) { cout << " " << i << " " << rand ( ) << "\n"; } cout << "\n"; cout << "2: Let seed be 123, call srand ( seed ).\n"; cout << "\n"; seed = 123; srand ( seed ); for ( i = 1; i <= 5; i++ ) { cout << " " << i << " " << rand ( ) << "\n"; } seed = time ( 0 ); srand ( seed ); cout << "\n"; cout << "3: Let seed be time(0) = " << seed << ", call srand ( seed ).\n"; cout << "\n"; for ( i = 1; i <= 5; i++ ) { cout << " " << i << " " << rand ( ) << "\n"; } cout << "\n"; cout << "4: Let seed be 1999, call srand ( seed ).\n"; cout << "\n"; seed = 1999; srand ( seed ); for ( i = 1; i <= 5; i++ ) { cout << " " << i << " " << rand ( ) << "\n"; } cout << "\n"; cout << "5: Let seed be 123, call srand ( seed ).\n"; cout << "\n"; seed = 123; srand ( seed ); for ( i = 1; i <= 5; i++ ) { cout << " " << i << " " << rand ( ) << "\n"; } cout << "\n"; cout << "6: Let seed be 123, call srand ( seed )\n"; cout << " but do this before EVERY call.\n"; cout << "\n"; seed = 123; for ( i = 1; i <= 5; i++ ) { srand ( seed ); cout << " " << i << " " << rand ( ) << "\n"; } seed = time ( 0 ); srand ( seed ); cout << "\n"; cout << "7: Let seed be time(0) = " << seed << ", call srand ( seed ).\n"; cout << "\n"; for ( i = 1; i <= 5; i++ ) { cout << " " << i << " " << rand ( ) << "\n"; } return 0; }