Skip to content

Instantly share code, notes, and snippets.

@mebtte
Created April 24, 2019 08:10
Show Gist options
  • Select an option

  • Save mebtte/26ccd015665eb58cfc72d5a11de2d546 to your computer and use it in GitHub Desktop.

Select an option

Save mebtte/26ccd015665eb58cfc72d5a11de2d546 to your computer and use it in GitHub Desktop.
Get a random integer.
/**
* Get a random integer.
* @author mebtte<[email protected]>
* @param {Number} [min] Minimum integer, default `0`.
* @param {Number} [max] Maximum integer, default `1`.
* @return {Number} A random integer between `min` and `max` that include `min` but do not include `max`.
*/
function getRandomInteger(min = 0, max = 1) {
return Math.floor(min + Math.random() * (max - min));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment