// program to write 10 random integers to "integer.file"
//              and 10 random real numbers to "real.file"

// library for file streams
#include <fstream.h>

// library for stream I/O with the keyboard
#include <iostream.h>

// library for string class
#include <string>

// libraries for the random number generator
#include <stdlib.h>
#include <time.h>
//    time, from time.h,  returns a value based upon the time of day
//    rand , from stdlib.h, returns a random integer between 0 and MaxRandInt
//       the value of MaxRandInt is machine dependent:
//           2^32-1 = 2147483647 for SparkStations, 
//           2^15-1 = 32767 for IBM Xstation 140s and HP 712/60s
const int MaxRandInt = 32767;

int main (void)
{  ofstream file1, file2;	/* output file streams */
   int i;
   int ival;
   double rval;
   double MaxRandReal = (double) MaxRandInt;  /* make MaxRandInt a real */
   
   
   // initialize random number generator
   // change the seed to the random number generator, based on the time of day
   cout << "initializing random number generator" << endl;
   srand (time ((time_t *) 0) );

   // determine integer file name
   string filename;
   cout << "enter file name for the integer file: ";
   cin >> filename;

   // place integer values on first file
   cout << "generating file of integers" << endl;
   file1.open (filename.c_str());

   for (i = 1; i <= 10; i++)
       { ival = rand ();   		/* two lines could be abbreviated */
         file1 << ival << endl;}	/* file1 << rand() << endl;       */
   file1.close ();

   // place real values on second file
   cout << "generating file of reals" << endl;
   file2.open ("real.file");

   for (i = 1; i <= 10; i++)
       { file2 << rand() / MaxRandReal << endl;}
   file2.close ();

   cout << "writing of files completed" << endl;
   return 0;
}
