Number
JavaScript Number: Cheetsheet
Categories:
Get random integer in the specific range
const getRandomIntegerRange = ({
min= 0,
max= 100,
}) => {
min = parseInt(min, 10);
max = parseInt(max, 10);
let randomInt = Math.floor(Math.random() * (max - min + 1)) + min;
return randomInt;
}
let random_integer = getRandomIntegerRange({
min: 3,
max: 11
});
console.log(random_integer);
Random Integer
// Returns a random integer from 0 to 9:
Math.floor(Math.random() * 10);
// Returns a random integer from 0 to 10:
Math.floor(Math.random() * 11);