Random without repeat
UltimateCreatives
Member Posts: 27
Hi. I thought it will be simple but ...
All i want to do is to pick for example 4 words from group of 10. All ten words are put in table. When I pick up first word and display it on the screen, everything it's ok. When I pick up second one it's also ok in case it's not the same word as first one. The same thing it with the third one and thourt.
I tried to do something like that.
I have made 4 attributes. Random1, Random2, Random3 and Random4. When I pick up first one from the table: random(1,tableRowCount(game.tablexxx )), I contrain attribute Random1 to number of row in table of the first word.
When I try do to the same with second word, I use the same rule, but I add the rule that if Attribute Random2 equals Random1 i repeat my random rule. The problem is, that sometimes it pick up the same number again.
It means that I have only two attempts to try to avoid picking up the same number. The problem is getting bigger when we do the same with number 3 and number 4.
What shoud be done? There should be made some kind of loop like random(1,tableRowCound(game,tablexxx)), until Random2 is not equal Random1. And then random(1,tableRowCound(game,tablexxx)), antul Random 3 id not equal Random 2 and not equal Random1 etc etc.
Any idea how to do it?
Kind regards
All i want to do is to pick for example 4 words from group of 10. All ten words are put in table. When I pick up first word and display it on the screen, everything it's ok. When I pick up second one it's also ok in case it's not the same word as first one. The same thing it with the third one and thourt.
I tried to do something like that.
I have made 4 attributes. Random1, Random2, Random3 and Random4. When I pick up first one from the table: random(1,tableRowCount(game.tablexxx )), I contrain attribute Random1 to number of row in table of the first word.
When I try do to the same with second word, I use the same rule, but I add the rule that if Attribute Random2 equals Random1 i repeat my random rule. The problem is, that sometimes it pick up the same number again.
It means that I have only two attempts to try to avoid picking up the same number. The problem is getting bigger when we do the same with number 3 and number 4.
What shoud be done? There should be made some kind of loop like random(1,tableRowCound(game,tablexxx)), until Random2 is not equal Random1. And then random(1,tableRowCound(game,tablexxx)), antul Random 3 id not equal Random 2 and not equal Random1 etc etc.
Any idea how to do it?
Kind regards
Comments
Instead of putting position coordinates in the table, put whatever you have instead.