JS 随机数

参考:https://www.cnblogs.com/wisewrong/p/10517532.html

参考知乎回答:https://www.zhihu.com/question/22818104

 

1. random, 伪随机数

2.sort重排,取其中

3.洗牌算法

4.9301, 49297, 233280神数字,线性同余生成器,Hull-Dobell定理

var rand = (function(){ 
   var seed = (new Date()).getTime();
   function r(){ 
        seed = (seed*9301+49297)%233280 
        return seed/(233280.0) 
   } 
   return function(number){ 
         return Math.ceil(r()*number) 
    }
 })()

 

posted @ 2019-06-28 15:26  Loki-Liu  阅读(385)  评论(0编辑  收藏  举报