I want 3 different enemies to appear in a random order, but never two the same after each other.
- By choosing one at random, it often happens that the same enemy appears even three or more times in a row.
- With an advanced random permutation table
(-> AdvancedRandom: Create permutation with 3 values starting at 0)
that I shuffle every 3 'appearances', I often get the same enemy two times in a row (example of a sequence: 0, 1, 2, 2, 1, 0, 0, 2, 1, 1, 2, 0).
- So when shuffling the permutation table I check if the last enemy (of the first table) and the first enemy (of the new table) are not the same. Else I reshuffle.
However, I feel that this is a very complex and far-fetched solution. Can it also be simpler?
[functions]
| Local static number index = 0
----* On function 'getNext' → Number
--------+ System: index < 2
---------> Functions: Set return value AdvancedRandom.Permutation(index)
---------> System: Add 1 to index
--------+ System: Else
--------+ System: index = 2
---------> Functions: Set return value AdvancedRandom.Permutation(2)
---------> Functions: Call randomizeTable
---------> System: Set index to 0
| Local number last = 0
----* On function 'randomizeTable'
-----> System: Set last to AdvancedRandom.Permutation(2)
-----> AdvancedRandom: Shuffle permutation table
--------+ System: While
--------+ System: last = AdvancedRandom.Permutation(0)
---------> AdvancedRandom: Shuffle permutation table
Thanks!
Wim