您的位置:首页 > Web前端 > JavaScript

生成javascript随机数

2014-09-04 14:19 204 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: