moonsnow

 一个简单的函数,产生随机整数:

 

  1. function rnd(start, end){
  2.     return Math.floor(Math.random() * (end - start) + start);
  3. }

 

如rnd(10, 100)将产生10~100之间的整数,其中Math.random()产生0-1的随机数,乘以(100-10)将得到0~90的数,再加上10得到10~100的数,然后用Math.floor对该结果取整。

分类:

技术点:

相关文章:

  • 2021-10-18
  • 2021-12-24
  • 2022-12-23
  • 2021-11-03
  • 2021-10-24
  • 2022-12-23
  • 2022-03-03
猜你喜欢
  • 2022-12-23
  • 2022-02-22
  • 2022-12-23
  • 2021-12-04
  • 2022-12-23
  • 2021-08-01
相关资源
相似解决方案