//////////////////////////////////////////////////////////////////////////////
//
//  Author:       Shawn Stoffer
//
//  Description:  This program is meant to simply create a list of random
//                numbers (presumably used for testing of some other program,
//                like, say, a binary tree structure, or sorting or something).
//                This program asks for how many numbers you would like to have
//                in the output, and then where you would like to place the
//                output.  A slightly better way to do this would be to make
//                it output to standard output if the file was not openable, 
//                or if the user specifies no file to output to, so that it 
//                could maybe be used in a batch mode... 
//  
//  Compiler:     g++, this file compiles cleanly with the -Wall option, but
//                not the -pedantic option, though this is because of the 
//                STL string class, not due to this program specifically.
//
//  System:       This program should compile on any system (that has a C++ 
//                 compiler...)
//  
//////////////////////////////////////////////////////////////////////////////

#include <iostream> // cin, cout, cerr (standard input/output)
#include <fstream>  // the fstream class, file input/output
#include <string>   // the string class (STL)
#include <time.h>   // the time() function.

int main(void) {
  int n;
  // Use the string class, it is more reliable, and less problematic than the
  // standard char* (C) strings, and cleaner, though it does have more
  // overhead.
  string outf;
  
  // I probably should make it check for arguments to the program here, and
  // if there are check to see if the user wants to run in batch mode...but,
  // alas, another day.

  // Prompt the user for the number of numbers, and the output file.
  cout << "Please input how many numbers you would like in the output : ";
  cin >> n;
  cout << endl << "What file would you like to place the output in : ";
  cin >> outf;
  cout << endl;

  // open the output file, and check to make sure that the file is valid.  
  ofstream outfile(outf.data());
  if (!outfile) {
    cerr << "Cannot open output file " << outf << " EXITING!!!" 
         << endl << endl;
    exit(1);
  }
  
  // Seed the random number generator.
  srand(time(0));

  // Generate the numbers.
  for (int i=0; i<n; i++) {
    
    // make sure that the random number falls between 0 and 9999.  We should 
    // probably take out the magic number (10000) and replace it with a
    // constant, or better yet, have the user enter it, but that is left as 
    // an excersize to the reader.
    outfile << rand()%10000 << " ";
    
    // If we have ten numbers, then insert a newline, this will not 
    // affect the output, as anyone just doing a cin >> (int) will not
    // know the difference, as cin ignores whitespace, but it makes the 
    // output prettier.
    if ((i%10)==9) outfile << endl;
  }
  
  return 0;
}


