#include "BoostRandom.h"

const FloatType BoostRandom::defaultFloatFrom = static_cast<FloatType>( 0.0 );
const FloatType BoostRandom::defaultFloatTo = static_cast<FloatType>( 100.0 );
const int BoostRandom::defaultIntFrom = 0;
const int BoostRandom::defaultIntTo = 100;

BoostRandom::BoostRandom() : Random(),
    generator( getSeed<boost::uint32_t>() ),
    dist_bool( /* default=0.5 */ ),
    dist_01( generator ),
    floatFrom( defaultFloatFrom ), floatTo( defaultFloatTo ),
    dist_float( generator, RealDistribution( floatFrom, floatTo ) ),
    intFrom( defaultIntFrom ), intTo( defaultIntTo ),
    dist_int( generator, IntegerDistribution( intFrom, intTo ) ) { /* Empty */ }

bool BoostRandom::getBit() {
  return dist_bool( generator );
}

FloatType BoostRandom::get01() {
  return dist_01();
}

FloatType BoostRandom::getFloat( FloatType from, FloatType to ) {
  if ( to != floatTo || from != floatFrom ) {
    dist_float = RealGenerator( generator, RealDistribution( from, to ) );
    floatFrom = from; floatTo = to;
  }
  return dist_float();
}

int BoostRandom::getInt( int from, int to ) {
  if ( to != intTo || from != intFrom ) {
    dist_int = IntegerGenerator( generator, IntegerDistribution( from, to ) );
    intFrom = from; intTo = to;
  }
  return dist_int();
}
