rafaelmaeuer
8/10/2017 - 7:31 AM

Generating random whole numbers in JavaScript in a specific range? - From https://stackoverflow.com/questions/1527803/generating-random-whol

Generating random whole numbers in JavaScript in a specific range? - From https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range

/**
 * Returns a random number between min (inclusive) and max (exclusive)
 */
function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
}

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