且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在JavaScript中生成两个数字之间的随机数

更新时间:2023-02-10 12:17:59

如果你想得到1到6之间,你会计算:

If you wanted to get between 1 and 6, you would calculate:

Math.floor(Math.random() * 6) + 1  

其中:


  • 1是起始编号

  • 6是可能结果的数量(1 + start ( 6) - 结束(1)

  • 1 is the start number
  • 6 is the number of possible results (1 + start (6) - end (1))