Skip to main content Accessibility Feedback

randomNumber.js

Get a random integer with a minimum and maximum value.

Works in all modern browsers, and at least back to IE9.

/*!
 * Get a random integer with a minimum and maximum value
 * (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com
 * @param  {Integer} min  The minimum value
 * @param  {Integer} max  The maximum value
 * @return {Integer}      A random number
 */
var randomNumber = function (min, max) {
	return Math.floor(Math.random() * (max - min + 1) + min);
};