我是靠谱客的博主 虚拟冬日,这篇文章主要介绍不使用Math.random实现随机数,现在分享给大家,希望可以做个参考。

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

最后

以上就是虚拟冬日最近收集整理的关于不使用Math.random实现随机数的全部内容,更多相关不使用Math内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(146)

评论列表共有 0 条评论

立即
投稿
返回
顶部