Hi there,
I got a shuffle-algorithm like this one: https://www.scirra.com/tutorials/599/simple-array-shuffle
local var: pick=0
1| Event: System | Repeat Array_Temp.Width times
2| Action: Array_Temp | Set value at loopindex to loopindex
1|Event: System | Repeat Array_Music.Width times
2|Action: System | set pick to floor(random(Array_Temp.Width))
3|Action: Array_Music | Set value at loopindex to Array_Temp.At(pick)
4|Action: Delete index pick from X axis
Problem is, I want to be sure that the values in the array don't match their element-index, which can easily happen with the algorithm above. So i wrote a small addition:
local var: pick=0
local var: loopindex_repeat
1| Event: System | Repeat Array_Temp.Width times
2| Action: Array_Temp | Set value at loopindex to loopindex
1|Event: System | Repeat Array_Music.Width times
2|Action: System | set pick to floor(random(Array_Temp.Width))
3|Action: System | set loopindex_repeat to loopindex
4|-- Event: System | While
System | loopindex_repeat = Array_Temp.At(pick)
5|-- Action: System | set pick to floor(random(Array_Temp.Width))
6|Event: 'blank'
7|Action: Array_Music | Set value at loopindex to Array_Temp.At(pick)
8|Action: Array_Temp | Delete index pick from X axis
This seems to do the trick, but:
1) why do i need to floor the random when setting the variable? doesn't seem to make a difference without it.
2) possible bug: could this resolve in an infinite loop when the only value in Array_Temp left matches the last index i want to fill in Array_Music (in my case index=7, value=7 since the array-width is 8)?
3) i declared the variable loopindex_Repeat, cause i'm not sure if the loopindex-expression in the while-loop referes to the while-loop or the repeat-loop.