Reputation: 1
The app works like this: you fling the sprite and the sprite starts bouncing from edge to edge on your screen. When the sprite hits the edge it should change the image (example of the numbers now: 2 1 1 3 2 3 1 2 2 2 3 ...) but the problem is it can repeat the same number in a row so it's 2 and again 2 but I want them to be random and to not repeat themselves in a row (example how I want them to be: 1 3 2 3 1 3 2 1 2 3 2 3 1 2 1 ...)
This is a video of the app working: https://i.sstatic.net/rvib3.jpg
Upvotes: 0
Views: 217
Reputation: 6293
the problem is it can repeat the same number in a row so it's 2 and again 2 but I want them to be random and to not repeat themselves in a row
store the latest random number in a variable and repeat getting a random number if you got the same number as already stored.
Alternatively you can modify this solution to your needs: How to pick a random item from a list without picking duplicates?
Upvotes: 1