Skip to main content

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

"use strict";

var randomIntegerInRange = function randomIntegerInRange(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
};