JavaScript 生成随机数需要用到 Math.random() 和 Math.floor()
Math.random() 生成一个0(包含)到1(不包含)之间的浮点数。
随机生成(1到10,10不包含)
公式:Math.floor(Math.random()*(max-min)+min
Math.floor(math.random()*(10-1))+1
随机生成(1到10,10包含)
公式:Math.floor(Math.random()*(max-min+1))+min
Math.floor(math.random()*(10-1+1))+1