先上代码:
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/question/22818104

更多推荐

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