/*
 * random.cpp
 *
 * Implementation of the Random class.  See header file for function
 * descriptions.  Based on the code provided in the ISO C specification.
 *
 */

#include <cstdlib>
#include <ctime>
using namespace std;

#include "random.hpp"

Random::Random() 
    : state_(time(NULL))
{
    // Nothing else to do.
}

Random::Random(unsigned long seed)
    : state_(seed)
{
    // Nothing else to do.
}

int Random::next()
{
    state_ = state_ * MULTIPLIER + ADDITIVE;
    return (state_ / DIVISOR) % MAX;
}

int Random::next(int range)
{
    int rawRandom = next();
    return (rawRandom * range) / MAX;
}
