Skip to content

Instantly share code, notes, and snippets.

@bronzehedwick
Last active April 29, 2016 13:56
Show Gist options
  • Save bronzehedwick/688b8727c41cec06bb92 to your computer and use it in GitHub Desktop.
Save bronzehedwick/688b8727c41cec06bb92 to your computer and use it in GitHub Desktop.
Random whole number generator.
/**
* Returns a random number between min and max, rounded to the nearest whole number.
* @param {number} min is the lowest amount possible to return.
* @param {number} max is the highest amount possible to return.
* @returns {number} a random number between min and max.
*/
let random = (min, max) => Math.round(Math.random() * (max - min) + min);
/**
* Returns a random number between min and max, rounded to the nearest whole number.
* @param {number} min is the lowest amount possible to return.
* @param {number} max is the highest amount possible to return.
* @returns {number} a random number between min and max.
*/
function random(min, max) {
return Math.round(Math.random() * (max - min) + min);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment