xxxxxxxxxx
// Output between 1 to 10
const min = 1, max = 10;
console.log(Math.floor(Math.random() * (max - min + 1)) + min);
xxxxxxxxxx
// Between any two numbers
Math.floor(Math.random() * (max - min + 1)) + min;
// Between 0 and max
Math.floor(Math.random() * (max + 1));
// Between 1 and max
Math.floor(Math.random() * max) + 1;
xxxxxxxxxx
function randomInRange(min, max)
{
return Math.floor(Math.random() * (max - min + 1) + min);
}
xxxxxxxxxx
Math.floor(Math.random() * (max - min + 1)) + min;
// Between 0 and max
Math.floor(Math.random() * (max + 1));
// Between 1 and max
Math.floor(Math.random() * max) + 1;
xxxxxxxxxx
function randomIntFromInterval(min, max) { // min and max included
return Math.floor(Math.random() * (max - min + 1) + min)
}
const rndInt = randomIntFromInterval(1, 6)
console.log(rndInt)