Skip to content

Instantly share code, notes, and snippets.

@ccondry
Last active March 4, 2021 17:21
Show Gist options
  • Save ccondry/cebd130bd0269c56ffbf004c6b046bc4 to your computer and use it in GitHub Desktop.
Save ccondry/cebd130bd0269c56ffbf004c6b046bc4 to your computer and use it in GitHub Desktop.
choose random integer between min and max, inclusively
function randomInt (min, max) {
const range = max - min
if (range < 0) {
throw Error('cannot generate random int with min-max range less than 0')
}
const r = Math.random()
return Math.round(r * range + min)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment