#include "Random.h"

namespace irr
{
namespace core
{

// Thanx to Mike West for this Code

////
// since rand is weak, I implement my own random numbers


int rnd_a = 12345678;
int rnd_b = 12393455;
int rnd_c = 45432838;

void randomize(unsigned int a )
{
	rnd_a = a;
	rnd_b = 12393455;
	rnd_c = 45432838;
}

unsigned int	rnd_my()
{
	static int rnd_a = 12345678;
	static int rnd_b = 12393455;

	rnd_a = rnd_a ^ 0x10010100;
	rnd_a = (rnd_a << 1) | ((rnd_a>> 31)&1);
	rnd_a ^= rnd_b;
	rnd_b = rnd_b * 255 + 32769;
	unsigned int return_value = rnd_a;
	return return_value;
}

// return random number in the range 0 .. a-1
int rndi (unsigned int a)
{
	return rnd_my() % a;
}

// return random number in the range 0 .. f
float rndf(float f )
{
	return f*(float)rnd_my()/4294967296.0f;
}

float rnd(float f1, float f2)
{
	return f1 + (f2-f1)*(float)rnd_my()/4294967296.0f;
}


};
};
