js的随机数生成器,不再使用Math.random

先上代码:
var randomNum = (function(){
var today = new Date();
var seed = today.getTime();
function rnd(){
seed = ( seed * 9301 + 49297 ) % 233280;
return seed / ( 233280.0 );
};
return function rand(number){
return Math.ceil(rnd(seed) * number);
};
})();

测试下:
console.log(randomNum(100))
console.log(randomNum(100))
console.log(randomNum(100))

为神马会使用9301,49297和233280这几个数字?原理见这里 http://www.zhihu.com/question/22818104

你可能感兴趣的:(javascript,HTML5,css)