Javascript Math Random Int Numbers

Description

Javascript Math Random Int Numbers


// Will return a whole number between min (inclusive) and max (exclusive)
// Note that we use floor() instead of round() to correct for an uneven distribution of numbers
Math.randomInt = function(min, max) {
     return min + Math.floor(Math.random() * (max - min + 1));
}

console.log(Math.randomInt(1,10));



PreviousNext

Related