Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save viniceosm/b83183c0d43c878b8b97dfa87ac33aba to your computer and use it in GitHub Desktop.
Save viniceosm/b83183c0d43c878b8b97dfa87ac33aba to your computer and use it in GitHub Desktop.
javascript-generate-random-number-except-some-values
function generateRandom(min, max) {
var num = Math.floor(Math.random() * (max - min + 1)) + min;
return ([8, 15].includes(num)) ? generateRandom(min, max) : num;
}
// except 8, 15
var test = generateRandom(1, 2000)
console.log(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment