> cat rand1.C // file rand1.C, cs2223, D97/98 // // test of random number generator // 10Apr98 NW, First version // includes #include "headers.h" // main() int main () { int first; while (1) { cout << "please enter your lucky number: "; cin >> first; if (first < 0) return 0; // exit condition srand(first); // use to seed random number generator int counter = 0; while (rand() != first) counter++; // count until first repeats cout << first << " wasn't that lucky, it didn't repeat until " << counter << " tries" << endl; } return 0; } // end main() // Copyright 1998 Norman Wittels > g++ rand1.C > a.out please enter your lucky number: 0 0 wasn't that lucky, it didn't repeat until 0 tries please enter your lucky number: 1 1 wasn't that lucky, it didn't repeat until 8001 tries please enter your lucky number: 2 2 wasn't that lucky, it didn't repeat until 52293 tries please enter your lucky number: 3 3 wasn't that lucky, it didn't repeat until 3723 tries please enter your lucky number: 4 4 wasn't that lucky, it didn't repeat until 33874 tries please enter your lucky number: 5 5 wasn't that lucky, it didn't repeat until 1203 tries please enter your lucky number: 6 6 wasn't that lucky, it didn't repeat until 3964 tries please enter your lucky number: 7 7 wasn't that lucky, it didn't repeat until 6126 tries please enter your lucky number: 8 8 wasn't that lucky, it didn't repeat until 2500 tries please enter your lucky number: 9 9 wasn't that lucky, it didn't repeat until 17933 tries please enter your lucky number: 10 10 wasn't that lucky, it didn't repeat until 33561 tries please enter your lucky number: -3 >