1+ Math.randomInt(x) Random numbers without duplicates

Hi friend.


How prevent same number sort with the variable fonction


1+ Math.randomInt(4)


I do a Loop for 10 time


And i have example


2-4-1-3-3-3-4-5


How prevent the [3-3-3]


i need force alway new number


tank you
The only way would be to store the previous number, and if you get the same number again, reroll.


However, be advised that by doing this you are no longer making your roll random. Random rolls can and do return the same number in a row. In fact, with a number of 4, you always have a 25% chance of getting the same number as you did previously.
The only way would be to store the previous number, and if you get the same number again, reroll.


However, be advised that by doing this you are no longer making your roll random. Random rolls can and do return the same number in a row. In fact, with a number of 4, you always have a 25% chance of getting the same number as you did previously.

yes i do it with rpgmaker variable, but i would like shortcut in javascript 🙂


If possible
That I don't know. It would require changing the random roll system in the engine, and that would change it for everything! And keep in mind again you would be breaking it to no longer be truly random, which might have interesting effects on the rest of your game.
If there are only a set number of options (like all integers between 0 and 100), you should put all of them in an array, shuffle it and pick the first x entries, which are guaranteed to be unique without randomly rolling the same number a dozen times in a row.
If there are only a set number of options (like all integers between 0 and 100), you should put all of them in an array, shuffle it and pick the first x entries, which are guaranteed to be unique without randomly rolling the same number a dozen times in a row.

i found great solution with the LABEL and CONDITIONAL


Tank you both 🙂

Original thread: https://forums.rpgmakerweb.com/threads/1-math-randomint-x-random-numbers-without-duplicates.60516/