Win*_*ung 19 javascript random
如何生成7到10之间的数字?到目前为止,我所知道的是在0-10的范围内产生:
Math.floor(Math.random()*11)
Run Code Online (Sandbox Code Playgroud)
Jor*_*dan 62
function getRandom(min, max) {
return min + Math.floor(Math.random() * (max - min + 1));
}
for(var x = 0; x < 5; x++) {
alert(getRandom(7, 10));
}
Run Code Online (Sandbox Code Playgroud)