Skip to content

Instantly share code, notes, and snippets.

@billmei
Last active December 17, 2015 17:39
Show Gist options
  • Save billmei/5647545 to your computer and use it in GitHub Desktop.
Save billmei/5647545 to your computer and use it in GitHub Desktop.
Return a random integer with JavaScript
function randInt (maximum) {
return Math.floor(Math.random() * maximum);
}
function randBetween (minimum, maximum) {
return Math.floor(Math.random() * (maximum - minimum) + minimum);
}
// This version is not zero-indexed
function randIntPlusOne (maximum) {
return Math.floor(Math.random() * maximum + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment