js随机生成[n,m)的数字(不包括m)

Math.random();//随机生成0到1的数字

Math.floor();//取小整

Math.floor(Math.random()*(最大值 - 最小值) + 最小值)

生成2到8的数:Math.floor(Math.random()*(8 - 2) + 2)

原文地址:https://www.cnblogs.com/YAN-HUA/p/9410578.html