码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-09-02 17:29:24      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:http   io   使用   java   ar   cti   log   on   c   

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实现随机数。

标签:http   io   使用   java   ar   cti   log   on   c   

原文地址:http://www.cnblogs.com/rubylouvre/p/3951778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!