Skip to content

Instantly share code, notes, and snippets.

@LB-Digital
Created December 21, 2018 13:14
Embed
What would you like to do?
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