Shuffle values in variables using layers
Mar 02, 2020
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
I think you would be better off building an array in javascript and then reading each of the values
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:
There should be no cross-platform issues with javascript.
It is much easier to generate an array with no duplicates and then assign to variables, if i get time today i will write one.
That would be great! Thanks!
Hi Steven,
I had a project where I did this to shuffle the numbers 1 - 10.
I updated the project to shuffle 1 - 30.
Ha! I knew Russell would beat me to it
Sent from my iPhone
Hey Phil,
You should still share your javascript solution. It would be much simpler to do instead of using all of those triggers.
Wow! It works!
Thank you so much Russell.
This discussion is closed. You can start a new discussion or contact Articulate Support.