#include "StdRandom.h"

#include <cstdlib>

StdRandom::StdRandom() : Random() {
  std::srand( getSeed<unsigned int>() );
}

bool StdRandom::getBit() {
  return ( getInt( 0, 1 ) == 0 ) ? false : true;
}

FloatType StdRandom::get01() {
  return static_cast<FloatType>( std::rand() ) / static_cast<FloatType>( RAND_MAX );
}

FloatType StdRandom::getFloat( FloatType from, FloatType to ) {
  const FloatType a = ( to - from ) / static_cast<FloatType>( RAND_MAX );
  const FloatType x = static_cast<FloatType>( std::rand() );
  const FloatType b = from;
  return a * x + b;
}

int StdRandom::getInt( int from, int to ) {
  return ( std::rand() % ( to - from + 1 ) ) + from;
}
