Skip to content

Instantly share code, notes, and snippets.

@LB-Digital
Created December 21, 2018 13:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save LB-Digital/d91fe7eb6a3ad0e52db4aee75acaa4ef to your computer and use it in GitHub Desktop.
Random integer between min, max values
/**
* 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