/* http://www.jokes2000.com/html/randomnumbers/

//how to use:
var randgen = new RandomNumberGenerator();
document.write('<p>'+randgen.nextMinMax(0,10)+'<p>'); //0 to 10 inclusive, no decimal. Example output: 7
document.write('<p>'+randgen.next()+'<p>'); //0 to 1, decimal. Example output: .8707143033365439
*/

//Return a random number. This method is part of the random number generator object.
function NextRandomNumber(){
	var hi   = this.seed / this.Q;
	var lo   = this.seed % this.Q;
	var test = this.A * lo - this.R * hi;
	if (test > 0) this.seed = test;
	else          this.seed = test + this.M;
	return (this.seed * this.oneOverM);
}

//Return a random number between min and max INCLUSIVE. This method is part of the random number generator object.
function NextRandomMinMax(min, max){
	return Math.round( (max-min) * this.next() + min );
}

//accepts a given seed. returns a random number generator object with method next.
function RandomNumberGenerator(num){
	this.seed = num;
	if(!this.seed){
		var d = new Date();
		this.seed = 2345678901 
			+ (d.getSeconds() * 0xFFFFFF) 
			+ (d.getMinutes() * 0xFFFF);
	}

	//Don't let the seed be larger than one.
	if(this.seed>=1){
		var str=this.seed+''; //http://www.javascripter.net/faq/converti.htm
		this.seed = Number(this.seed/Math.pow(10,str.length));
	}

	this.A = 48271;
	this.M = 2147483647;
	this.Q = this.M / this.A;
	this.R = this.M % this.A;
	this.oneOverM = 1.0 / this.M;
	this.next = NextRandomNumber;
	this.nextMinMax=NextRandomMinMax;

	//Flush out the first couple random numbers. These are often extremely low.
	this.next(); this.next();

	return this;
}

//This function is for one time stand alone use.
//Don't use it twice in one second or you'll get the same results.
//Possible better to use Math.random()
function CreateRandomNumber(Min, Max){
	var rand = new RandomNumberGenerator();
	return Math.round( (Max-Min) * rand.next() + Min );
}
