Created
December 21, 2018 13:14
-
-
Save LB-Digital/d91fe7eb6a3ad0e52db4aee75acaa4ef to your computer and use it in GitHub Desktop.
Random integer between min, max values
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
/** | |
* Using Math.round() results in an uneven distribution, as mentioned here... | |
* https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range | |
*/ | |
function randomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment