Learn how to get a random number between two numbers in JavaScript.
This JavaScript function always returns a random number between a minimum (included) and maximum number (excluded):
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min) ) + min;
}
Try it Yourself »
This JavaScript function always returns a random number between min and max (both included):
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}
Try it Yourself »
Read more about Random Numbers in our JavaScript Random Tutorial.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!