#pragma once
#include "../../stdafx.h"
#include "../glLibLocals.h"

#include "../glLibError.h"

namespace glLibMathRandom {
	inline double get_uniform(void) { return double(rand())/double(RAND_MAX); }
	inline double get_uniform(double left, double right) { return get_uniform()*(right-left)+left; }

	double get_gaussian(void);
	double get_gaussian(double mean, double stddev);
};

class glLibMathRandomDistrib {
	private:
		char _type;
		double _param1, _param2;
	public:
		glLibMathRandomDistrib(glLibFlagRandom type, double param1=0.0f, double param2=1.0f) {
			if (type==GLLIB_RANDOM_UNIFORM) _type = 1;
			else if (type==GLLIB_RANDOM_GAUSSIAN) _type = 2;

			#ifndef GLLIB_ERROR_MODE_REPORT_ERRORS
			else _type = 3;
			#else
			else if (type==GLLIB_RANDOM_NORMAL) _type = 3;
			else throw glLibError("Random type not recognized!");
			#endif

			_param1 = param1;
			_param2 = param2;
		}
		double sample(void) {
			switch (_type) {
				case 1: return glLibMathRandom::get_uniform(_param1,_param2); break;
				case 2: return glLibMathRandom::get_gaussian(_param1,_param2); break;
				case 3: return glLibMathRandom::get_gaussian(0.0,1.0); break;
			}
		}
};