Return a random whole number in a range.

This recipe will return a whole number between a lower and higher range. For a deeper discussion of this code, see this StackOverflow comment from Ionut Stan:

 * Returns a random integer between min and max
 * Using Math.round() will give you a non-uniform distribution!
function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;

Tags: math

comments powered by Disqus