Shuffle values in variables using layers

I'm trying to shuffle the numbers 1-30 in 30 variables for a memory-style game.

To do this, I populate the first variable from a random (no risk of a duplicate), then for variables 2-30, I have a succession of layers that generate a random value, then check if there's a match (i.e. duplicate) with each of the variables. If there is, it returns to generating another random number, if there isn't, the last layer assigns it and starts again.

I feel like I'm almost there, but I'm missing something because it only populates the first two variables. At one point, it populated the first fifteen, but not all.

8 Replies
Steven Chippendale

I have attempted to achieve this with JavaScript to no avail. I would prefer to avoid JavaScript for cross-platform compatibility, but if anyone has written a script for shuffling and assigning multiple values to the same number of variables, I would be grateful.

My previous attempt, which produced the same result (stopping at the second variable), was much simpler and used a single looping layer. It's much neater than my current attempt and therefore more practical for reusability - we quite regularly get requests for activities that 'shuffle' responses so there are no duplicates, rather than randomise.

Here is the single layer attempt: