Random Variables with no repeating value twice in a row.

I'm trying to roll values that does not repeat the result twice in a row, and would roll new values indefinitely until map transfer.

I followed something I found online, but I can't get it to work because the one I followed you have to actually choose to roll another number via choices. When what I wanted to do is to roll the numbers automatically with Wait intervals when you get a proper result.

Not sure if I make sense but below is my event.

Please let me know if this can be done in a simpler way, I intend to increase the number from 1-3 to maybe 1-5 in the future, but for now, random value 1-3 is good enough.
Maybe something like this would help?

Label: reroll
Control Var1 set to Random 1 to 5
If Var2 is not equal to Var1 than do:
-Control Var2 set to Var1 and do your number branches stuff from the Pictures.
else: jump to Label reroll
end.

Var2 will start as 0 and after the first randomization, it will save the value of the last random number.
The "easiest" way to prevent all repeats with any group of numbers would be to handle the numbers as elements in an array - which isn't really easy unless you have a solid intermediate knowledge in logic and javascript.

If you allow repeats but don't want the same result twice, then you can get it easier by using a second variable to store last result and reroll until they are different.

EDIT: ninja'd
Maybe something like this would help?

Label: reroll
Control Var1 set to Random 1 to 5
If Var2 is not equal to Var1 than do:
-Control Var2 set to Var1 and do your number branches stuff from the Pictures.
else: jump to Label reroll
end.

Var2 will start as 0 and after the first randomization, it will save the value of the last random number.
I will try this later and let you know how it goes! Thank you!
Maybe something like this would help?

Label: reroll
Control Var1 set to Random 1 to 5
If Var2 is not equal to Var1 than do:
-Control Var2 set to Var1 and do your number branches stuff from the Pictures.
else: jump to Label reroll
end.

Var2 will start as 0 and after the first randomization, it will save the value of the last random number.
I will try this later
The "easiest" way to prevent all repeats with any group of numbers would be to handle the numbers as elements in an array - which isn't really easy unless you have a solid intermediate knowledge in logic and javascript.

If you allow repeats but don't want the same result twice, then you can get it easier by using a second variable to store last result and reroll until they are different.

EDIT: ninja'd
Unfortunately, I’m not really good at scripting or JS, so I know I’m probably pushing the event commands as much as I can, but sometimes I just don’t understand what I’m doing wrong.
Maybe something like this would help?

Label: reroll
Control Var1 set to Random 1 to 5
If Var2 is not equal to Var1 than do:
-Control Var2 set to Var1 and do your number branches stuff from the Pictures.
else: jump to Label reroll
end.

Var2 will start as 0 and after the first randomization, it will save the value of the last random number.

UPDATE: It works perfectly!
Thank you very much! 🙏

This can be closed!

Original thread: https://forums.rpgmakerweb.com/threads/random-variables-with-no-repeating-value-twice-in-a-row.157306/