// This program demonstrates the use of the random number generator // // Run it and look at the output carefully // // AUTHOR: Jim Etheredge // // #include //#include // This is where the time functions are. //#include using namespace std; const int SIZE = 5; int main() { int arr[SIZE][SIZE] = {{0}}; int randRow, randCol; srand((unsigned)time(NULL)); // Seed the random number generator. // Do this only once for each set of // random numbers. For normal use // the seed value doesn't matter much. // Let's do this 8 times for(int howMany = 0; howMany < 8; howMany++) { // rand() returns integers between 0 and RAND_MAX (VERY LARGE) // so we scale them to fit randRow = rand() % SIZE; // Generate a random row randCol = rand() % SIZE; // Generate a random column if(arr[randRow][randCol] == 0) // If there isn't a number there, arr[randRow][randCol] = howMany + 1; // put a number there. // Print out the array so we can see the changes for(int i = 0; i < SIZE; i++) { cout << "| "; for(int j = 0; j < SIZE; j++) cout << arr[i][j] << ' '; cout << '|' << endl; } // End of print loop cout << "-------------" << endl; // This line needs some work. Why? } // End of outer loop } // End of program