GruntFish

 

因为js本身取随机数仅能取 0 到 1之间的数,所以.....

 

取 1 - 10之间的随机数.

 

function getSJS(x,y,z){
     var int = null;
     while(int >= x || int <= y || int === null){
            int = Math.random();
            int = (int.toFixed(z) * x).toFixed(0);
     }
      return int;
}

 

getSJS(10,1,3)

 

   X : 最大数(不包含) Y : 最小数(不包含)

  Z使返回的数更随意(有的数不能用,会有异常情况)

 

分类:

技术点:

相关文章:

  • 2021-12-23
  • 2021-12-24
  • 2021-11-30
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案