// Example random number code for CISC181
// P. Conrad, 2/19/2004

// Prompt user for integer "n".
// Program provides user with a random number between 1 and n.

// Program randomizes seed so that a different number is chosen each time.

#include <iostream>

using namespace std;

#include <cstdlib>  // needed to use the rand function
#include <ctime>  // needed to use the time function


int main(void)

{

  // seed the random number generator

  unsigned seed; // declare an unsigned integer to store a "seed"
                 // for the random number generator.

  seed = time (0); // returns the number of seconds since 00:00:00 UTC
                   // January 1, 1970.  This number will be different each
                   // time we run the program.

  srand (seed);   // seed the random number generator so we get different
                  // results each time we run the program.  We only need to
                  // do this once at the beginning of our program.

  // ask user for a value for n

  int n;

  cout << "Please enter value for n >";
  cin >> n;

  // test value for validity

  if (n<=0)
    {
      cerr << "Value " << n << " is not valid\n" 
	   << "Value should be greater than 0" << endl;
      exit (-1);
    }

  // generate five random numbers and print them out

  int randValue;
  int i = 1;

  while (i<=5)
    {
      randValue = rand() % n + 1; // rand () % n is between 0 and n-1
      cout << "Random value " << i << " is " << randValue << endl;
      i++; // increment loop counter
    }

  return (0);

}

