Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active June 11, 2022 07:24
Show Gist options
  • Save mr-pascal/f96f12b8e01f7a3aec7e9c0c44af8154 to your computer and use it in GitHub Desktop.
Save mr-pascal/f96f12b8e01f7a3aec7e9c0c44af8154 to your computer and use it in GitHub Desktop.
/**
* Returns a random integer between min (inclusive) and max (inclusive).
* @param {number} min The minimum value
* @param {number} max The maximum value
* @return {number} The random integer
*/
const getRandomInt = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(getRandomInt(0, 10));
/*
Output (e.g.):
3
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment