不使用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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM