Generates a random integer in the specified range.
Math.random()
to generate a random number and map it to the desired range.Math.floor()
to make it an integer.const randomIntegerInRange = (min, max) =>
Math.floor(Math.random() * (max - min + 1)) + min;
randomIntegerInRange(0, 5); // 2
JavaScript, Math
Generates an array of n
random integers in the specified range.
JavaScript, Math
Generates a random number in the specified range.
JavaScript, Math
Creates an array of numbers in the arithmetic progression, starting with the given positive integer and up to the specified limit.