How TO - Random Number Between Two Numbers
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
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):
Example
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.
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.