使用知识
Math.random()
返回 0 ~ 1 之间的随机数。 |
Math.round()
把数四舍五入为最接近的整数。 |
//生成一段5-10的随机数,公式(y-x)+x
for(var i=1;i<=10;i++)
console.log(Math.round(Math.random()*(10-5)+5))
使用知识
Math.random()
返回 0 ~ 1 之间的随机数。 |
Math.round()
把数四舍五入为最接近的整数。 |
//生成一段5-10的随机数,公式(y-x)+x
for(var i=1;i<=10;i++)
console.log(Math.round(Math.random()*(10-5)+5))