# Exclude some numbers from random number variable

#### Ina00

##### Regular
Let's say for example that I assign to a variable a random number from 1 to 10.
I'd like the chosen number to being removed from the count next time I assign a random number to that variable. (I'll accept any method do to this, even multiple event pages).

Example:
Variable = random 1-10 => Variable = 3

3 is removed from the count, so next time i assign a random number, "3" will never be chosen.

#### Andar

##### Regular
the only realistic way to do this is by using an array with elements, and that cannot be done by pure event commands.

basically you start by creating an array of ten elements, give each element one of the numbers from 1 to 10. then you get a random index number, remove the element of that index and use the number inside that element as the value.

Ruby/RGSS3 has functions for array elements, but I don't knoe their syntax, you'll have to search that for yourself.

#### BenSD

##### Could be anybody
There's not a way to event this directly, but there are ways to event around this.

Try sticking it in a loop and using switches to mark which numbers have already come up -- if the random number happens to be one that's been used (switched on), then it can just repeat the loop until it gets to one that isn't. If that doesn't make sense, I'm sorry and can post an example.

#### Andar

##### Regular
@BenSD that is a rather bad methology because it creates a lot of lag, especially with the last few numbers.

just imagine: you have already randomly rolled 19 of 20 numbers, and now have to loop around until the random function actually hits the last of the twenty numbers.
your method only works with a low number of elements and becomes extremely bad the more element are in the process.

#### Roninator2

##### Gamer
That's a good point Andar, I was thinking of doing random them save number picked into a second variable and check if it was picked but removing the numbers to pick from like was asked makes more sense. This is my thought so far, but I need to test it. Works
This could be done with script commands in the event.
Set a variable to the numbers you want
\$game_variables[xx] = [1,2,3,4,5,6,7,8,9,10]
get random number
\$game_variables[xx1] = rand[\$game_variables[xx].size)
get number from array
\$game_variables[xx2] = \$game_variables[xx][\$game_variables[xx1]]
remove number from array
\$game_variables[xx].delete_at(\$game_variables[xx1])

Last edited:

#### gstv87

##### Regular
Code:
``````ary = [1,3,6,4]
loop
var = rand(10) + 1
while ary.includes?(var)``````

ish?
I'm a bit rusty in plain code.

#### Lord Vectra

##### Master Eventer
So, I just opened up my VX Ace, and I did what BenSD suggested using Andar's numbers (1-20) while I had stuff moving in the background (to detect any lag).

Now, I didn't use loop because I think loop is bad. I used Label and Jump to Label because that seems to work when Loop doesn't. From testing it, the only lag that pops up is when you have all numbers excluded so the game just freezes as its stuck at getting a random number... forever. Even if all but the number 20 is excluded, you should see no lag. The Makers are pretty quick at proccessing. I did Label Redo at the top, the random number right below, and then I checked for each number the variable could've been and to make it easy, I made the Switch ID the same so if it hits 6, Switch will turn on. If said switch is already on, it'll just to Label Redo which is at the top, so it'll never finish until it hits a number it hasn't already hit.

#### Ina00

##### Regular
I really thank you all so much for helping!!
I used @Roninator2 's method and it perfectly works.

I created the array outside of the event because I thought it would reset with the interaction.

Again, a big thank to you all : D

#### Roninator2

##### Gamer
I created the array outside of the event because I thought it would reset with the interaction.
The way I showed it, it would. Glad you figured that out.
Happy you used my method. Doesn't happen often that I have a simpler or better way than others.
Maybe I'm getting better/smarter.
Happy game making

#### Ina00

##### Regular
The way I showed it, it would. Glad you figured that out.
Happy you used my method. Doesn't happen often that I have a simpler or better way than others.
Maybe I'm getting better/smarter.
Happy game making
Thank you <3

### Latest Profile Posts

The Open Hand scandal got even more spicy. The Completionist streamer Jirard made a video response and tossed a bunch of links and documents, but apparently none of it actually addressed why donations he collected sat for 10 years (way too long to justify). He also seemed to threaten defamation suits vs. people for what amounts to pointing out publicly available records. The IRS should definitely audit.
My next update is going to amazing! There's been major additions and things I've wanted to do in previous versions that weren't possible until now. It's not ready yet, but will be soon!
made an RTP edit to try to save on work, found out I was editing the wrong tilesheet of cliffs.
It's fine... I'm fine... I'm sure fixing this won't take too long
Proud of the work done.
Probably gonna toss out some cameos.
-Message sponsored by the β Gang.