JS 获取随机数

1、Math.random()
返回一个浮点数, 伪随机数在范围从0到小于1,也就是说,从0(包括0)往上,但是不包括1(排除1)
2、Math.floor(x)
返回小于一个数的最大整数,即一个数向下取整后的值。

Math.floor( 15.95);//15

获取1-10的随机整数

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

获取1-100的随机整数

Math.floor((Math.random()*100)+1)
原文地址:https://www.cnblogs.com/qingheshiguang/p/15011096.html