Last active
June 11, 2022 07:24
-
-
Save mr-pascal/f96f12b8e01f7a3aec7e9c0c44af8154 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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