Start of main content
Random number in range
JavaScript, Math, Random · Oct 22, 2020

Generates a random number in the specified range.
- Use
Math.random()
to generate a random value, map it to the desired range using multiplication.
const randomNumberInRange = (min, max) => Math.random() * (max - min) + min;
randomNumberInRange(2, 10);
More like this

Quickly and easily generate random integers, strings, booleans, arrays and hex color codes using JavaScript.
Collection · 7 snippets

Generates an array of n
random integers in the specified range.
JavaScript, Math · Oct 22, 2020

Generates a random integer in the specified range.
JavaScript, Math · Oct 22, 2020

Calculates the sum of the powers of all the numbers from start
to end
(both inclusive).
JavaScript, Math · Oct 22, 2020