Last active
March 4, 2021 17:21
-
-
Save ccondry/cebd130bd0269c56ffbf004c6b046bc4 to your computer and use it in GitHub Desktop.
choose random integer between min and max, inclusively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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