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

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
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
 
Last edited by a moderator:

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
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
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
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.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
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.
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
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 :)
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,867
Messages
1,017,061
Members
137,575
Latest member
akekaphol101
Top