Last active
April 9, 2020 04:47
-
-
Save Adrian-Samuel/2f3dd1b6ab1380287a6f276c8f9e2af6 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
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