/**
* 生成随机数的类,参数为随机数的种子,如果种子相同,则生成的随机数序列一样。
*
* @param {String} seed 字符串的随机数种子0-1中间的随机数,不包括1
*/
function Random(seed) {
this.seed = this.hashCode(seed);
}
Random.prototype.hashCode = function(str) {
str = str + '';
var hash = 0;
if (str.length == 0) return hash;
for (i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
}
Random.prototype.rand = function(max) {
this.seed = (this.seed * 9301 + 49297) % 233280;
var t = this.seed / (233280.0);
return Math.abs(Math.ceil(t * max));
}