注册
登录

您现在的位置是:首页 > 学无止境

生成javascript随机数

木木彡82 2014-09-04 14:19:48 557人围观
var rand = (function(){
var today = new Date();
var seed = today.getTime();
function rnd(){
seed = ( seed * 9301 + 49297 ) % 233280;
r...
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


文章评论

  • 登录后评论

点击排行