Skip to main content

randomNumber

TS JS Deno

Returns a random number in the specified range.

Use Math.random() to generate a random value, map it to the desired range using multiplication.

typescript
const randomNumber = (min, max) => Math.random() * (max - min) + min;
typescript
randomNumberInRange(2, 10); // 6.0211363285087005