/* RandomInt.cpp defines the non-trivial RandomInt operations.

 * Written by: Joel C. Adams, Spring, 1993, at Calvin College.
 * Written for: C++: An Introduction To Computing.
 * Revised: Spring 1997, for C++: An Introduction To Computing 2e.
 * Revised: Summer 2001, for C++: An Introduction To Computing 3e.
 *
 * See RandomInt.h for the class declaration,
 *     RandomInt.doc for class documentation.
 ******************************************************************/

#include "RandomInt.h"

bool RandomInt::generatorInitialized = false;

void RandomInt::initialize(int low, int high)
{
  myLowerBound = low;
  myUpperBound = high;

  if (!generatorInitialized)       // call srand() first time only
  {
     srand(long(time(0)));        // use clock for seed
     generatorInitialized = true;
  }

  myRandomValue = nextRandomInt();
}


void RandomInt::seededInitialize(int seedValue, int low, int high)
{
  myLowerBound = low;
  myUpperBound = high;
  srand(seedValue);
  generatorInitialized = true;
  myRandomValue = nextRandomInt();
}


RandomInt RandomInt::generate(int low, int high)
{
  assert(0 <= low);
  assert(low < high);
  myLowerBound = low;
  myUpperBound = high;
  myRandomValue = nextRandomInt();
  return *this;
}

