// 乱数発生クラス
// 汎用化失敗版
// 
// 書いた人：けけ＠ナニワアームズ商藩国
// 改変、自由。
// 再配布、自由。
// 一切の保証、なし。
// http://www.baroque-moon.com/BF27/s-w07_k.shtml
// 
// 参考にしたもの
//
// Ｃ言語による最新アルゴリズム事典　奥村晴彦著　技術評論社
//
// オブジェクト指向プログラム言語としてのJavaScript
// http://www.tokumaru.org/JavaScript/index.htm


// -------------------------------------------------
// 継承
function inherit(subClass, superClass) {
	for (var prop in superClass.prototype) {
		subClass.prototype[prop] = superClass.prototype[prop];
	}
}

// -------------------------------------------------
// 元になるクラス
function Random_Base()
{
	this.seed = 1;
	this.intMax = parseInt("0xffffffff");
}

// 初期化
function Random_Base_init(_seed)
{
	this.seed = _seed;
}

// 乱数取得
function Random_Base_get()
{
	return Math.random();
}

// _min <= n > _max の範囲
function Random_Base_getRange(_min, _max)
{
	return Math.floor( this.get() * (_max - _min)) + _min;
}

// _n 回読み捨て
function Random_Base_skip(_n)
{
	for (var i=0; i<_n; i++)
	{
		this.get();
	}
}

new Random_Base();
Random_Base.prototype.init = Random_Base_init;
Random_Base.prototype.get = Random_Base_get;
Random_Base.prototype.getRange = Random_Base_getRange;
Random_Base.prototype.skip = Random_Base_skip;



// ----------------------------------------------------
// 線形合同法
function Random_Linear()
{
	this.tmp = Random_Base;
	this.tmp();
	
	this.multiple = 69069;
}

// 初期化
function Random_Linear_init(_seed)
{
	this.seed = _seed;
	
	var mul = new Array(69069, 1664525, 39894229, 48828125, 1566083941, 1812433253, 2100005341);
	this.multiple = mul[this.seed % mul.length];
}

// 乱数取得
function Random_Linear_get()
{
	this.seed *= this.multiple;
	if (this.seed > this.intMax)
	{
		this.seed = this.seed % this.intMax;
	}
	return this.seed / (this.intMax + 1.0);
}


new Random_Linear();
inherit(Random_Linear, Random_Base);
Random_Linear.prototype.init = Random_Linear_init;
Random_Linear.prototype.get = Random_Linear_get;
