Is possible to looking for and random number except a list of numbers?

thats the question :

is possible this ? ; selecting a number betewenn 0 and 100 , but excluding for example the 5 or a list.

Phaser.Math.RND.integerInRange(0, 100, "except number 5");

thks in advance

Maybe with a do while loop?

const except = [5,7,8,9]
let randomNumber

do {
  randomNumber = Phaser.Math.RND.integerInRange(0,10)
} while (except.includes(randomNumber))

Don’t know if it works, I’m on my phone

1 Like

Another option, if you don’t want a (potentially) infinite loop in your code, is to generate an array with all the numbers between 0 and 100, except for the numbers you don’t want, and then use the pick method to get a random value out of that array.

2 Likes

Much better than my solution :grin:

1 Like

thks guys
I had a : do… while . but I am going to check “pick function”
have a nice day …