Skip to content

Instantly share code, notes, and snippets.

@Adrian-Samuel
Last active April 9, 2020 04:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adrian-Samuel/2f3dd1b6ab1380287a6f276c8f9e2af6 to your computer and use it in GitHub Desktop.
Save Adrian-Samuel/2f3dd1b6ab1380287a6f276c8f9e2af6 to your computer and use it in GitHub Desktop.
function getRandomNumber(min, max, blockList) {
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
if (blockList.includes(randomNumber)) return getRandomNumber(min, max, blockList)
return randomNumber
}
// Example on how to use
const result = getRandomNumber(1, 7, [1, 2, 3, 4, 5]) // can only ever return integers 6 or 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment