#include "cRandom.hpp"

/*** ANSI C Header Files ***/
#include <stdlib.h>
#include <time.h>

using MathEngine::cRandom;

/*static*/ cRandom* cRandom::sp_inst = nullptr;

cRandom::cRandom()
{
	Setup();
}

cRandom::~cRandom()
{}

/// Functions
/*static*/ cRandom& cRandom::Inst()
{
	if (sp_inst == nullptr)
		sp_inst = new cRandom();
	return *sp_inst;
}

/*static*/ void cRandom::Delete()
{
	delete sp_inst;
	sp_inst = nullptr;
}

const bool cRandom::Setup() const
{
	bool rtn = false;
	srand((unsigned int)time(nullptr));
	return rtn = true;
}

const unsigned long int cRandom::Rand( const unsigned long int max, const unsigned long int min /*= 0*/ ) const
{
	return (unsigned long int)rand() % max + min;
}

const float cRandom::Rand( const float max, const float min /*= 0.0f*/ ) const
{
	return (float)((max - min) * rand()/(float)RAND_MAX + min);
}

const double cRandom::Rand(const double max, const double min) const
{
	return (double)((max - min) * rand() / (double)RAND_MAX + min);
}

const long double cRandom::Rand(const long double max, const long double min) const
{
	return (long double)((max - min) * rand() / (long double)RAND_MAX + min);
}
