The following snippet returns a random number between min (inclusive) and max (exclusive).
// Returns a random number(float) between min (inclusive) and max (exclusive)
const getRandomNumber = (min, max) => Math.random() * (max - min) + min;
getRandomNumber(2, 10)
// Returns a random number(int) between min (inclusive) and max (inclusive)
const getRandomNumberInclusive =(min, max)=> {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
getRandomNumberInclusive(2, 10);