Skip to main content
File

title: randomInt tags: math,random,beginner

TS JS Deno

Returns a random integer in the specified range.

Use Math.random() to generate a random number and map it to the desired range, using Math.floor() to make it an integer.

const randomInt = (min, max) =>
  Math.floor(Math.random() * (max - min + 1)) + min;
randomInt(0, 5); // 2