Learn how to get a random number between two numbers in JavaScript.
Random Numbers
This JavaScript function always returns a random number between a minimum (included) and maximum number (excluded):
Example
js
function getRndInteger(min, max) {
return Math.floor(Math.random() *
(max - min) ) + min;
}
This JavaScript function always returns a random number between min and max (both included):
Example
js
function getRndInteger(min, max) {
return Math.floor(Math.random() *
(max - min + 1) ) + min;
}
Read more about Random Numbers in the JavaScript Random Tutorial.