思路分析
生成指定范围随机数 m~n之间的随机数 Math.random() [0~1) 之间随机数
0-10Math.floor(Math.random() * 10) + 0
10-20 Math.floor(Math.random() * 10) + 10
20-30 Math.floor(Math.random() * 10) + 20
30-50 Math.floor(Math.random() * 20) + 30
50-80 Math.floor(Math.random() * 30) + 50
m-n Math.floor(Math.random() * (n-m)) + m
具体代码
function getRandom(x,y){
var n = Math.max(x,y) //最大值
var m = Math.min(x,y) //最小值
var r = Math.floor(Math.random() * (n-m)) + m
return r
}
var rNum = getRandom(35,25)
document.write(rNum)