您的位置:首页 > 其它

不使用Math.random实现随机数。

2014-09-02 16:42 239 查看
var rand = (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(rand(100))
console.log(rand(100))
console.log(rand(100))
console.log(rand(100))
console.log(rand(100))
console.log(rand(100))
console.log(rand(100))
//原理参看这里 http://www.zhihu.com/question/22818104
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: