#include <iostream>
#include <cmath>
#include <ctime>
#include <fstream>

using namespace std;

void instructions();

int main(int argc, char *argv[])
{
	//make sure we were invoked with the right number of arguments
	if (argc != 2)
	{
		cout << "Usage:  a.exe [number of values]";
		return 0;
	}

	instructions();

	ofstream outfile;
	unsigned long numToGenerate = atoi(argv[1]);

	//seed the random number generator
	srand((unsigned long)time(NULL));

	//open the output file
	outfile.open("numbers.txt");

	cout << "Generating " << numToGenerate << " random integers..."<<endl;
	for(unsigned long count = 0; count < numToGenerate; count++)
	{
		outfile << rand() << " ";
	}
	cout << "Generation completed, "<<numToGenerate<<" random integers have been written to 'numbers.txt'."
		 <<endl<<endl;

	outfile.close();

	return 0;
}

void instructions()
{
	cout<<"This program will write 'N' random integers to an output file"<<endl
		<<"called 'numbers.txt', where 'N' is provided as a command-line"<<endl
		<<"argument.  All integers generated will be between 0 and RAND_MAX."<<endl
        <<endl<<endl;
}
