#include #include #include using namespace std; int main() { // randomize the "pseudo-random" number generator // (i.e. randomize the starting point for the // sequence of numbers) srand( time( 0 ) ); // This program will generate // "pseudo-random" numbers // The rand() function generates // a pseudo-random number in // the range 0 to RAND_MAX cout << "This program generates random numbers " << "in the range 0 to " << RAND_MAX << endl; int d1 = rand() % 6; // 0-5 d1++; // 1-6 cout << "Simulated die roll: " << d1 << endl; // write to a file using ofstream ofstream outfile; outfile.open( "die-rolls.txt" ); for ( int i = 0 ; i < 40000 ; i++ ) { int d = rand() % 6; // 0-5 d++; // 1-6 outfile << d << ' '; } outfile << endl; outfile.close(); return 0; }