#include #include const int MAXVALUE = 16; using namespace std; int main() { int numVals; int i, val; ofstream outfile("randomNums2.txt"); // use ifstream to input from a file srand(time(0)); // randomize (re-seed) the "random" number generator cout << "Write how many random values to the file? "; cin >> numVals; outfile << numVals << endl; for(i = 0; i < numVals; i++) { val = rand() % 16; // "random" numbers from 0..15 outfile << " " << val; if (i % 10 == 9) outfile << "\n"; // newline after each group of 10 values } outfile << "\n"; outfile.close(); return 0; } /* g++ -o randomNumFileCPP randomNumFile.cpp ./randomNumFileCPP Write how many random values to the file? 50 more randomNums2.txt 50 11 15 12 11 11 15 1 0 0 6 5 9 8 7 9 13 1 15 11 4 8 7 8 11 14 9 15 0 3 5 8 14 4 4 10 15 3 11 15 3 1 5 12 9 12 5 6 13 4 1 */