generate random, but unique values

Dec 29, 2020

Hi everyone,

I'm trying to create an activity where shapes are being displayed in a random order, by clicking on a button. I have created a variable, and assigned each of the shapes a specific value of that variable, plus a trigger that generates a random value of the variable each time the user clicks on the button. My problem is that the variable generates the same value more than once, so that some of the button clicks will not show any new shape. 

Can anyone help?

thanks,

Simona

1 Reply
Walt Hamilton

To create a learner experience with no lag time, you probably need to do this in javascript. If you have ten items, sort the numbers randomly, and send them back to SL in ten different variables. Then as you click, move through the variables, and set the state depending on the value of the variable.

However for some of us, js is difficult. Even if it isn't, I'm reluctant to use it because the people that follow me may not use it easily, and maintenance becomes a big problem for them. So I only use it as a last resort.

With that said, here are three ways to do what you want using only SL triggers.

Each slide is in its own scene, and they all scroll through seven states randomly without repeating any. I chose seven because you said you wanted states of different colors, and seven was easy number of colors. It should be noted that as SL gets into numbers six and seven, there is a lag as it randomly attempts to choose a number that hasn't been used before.

I tried to do this three different ways. On slide one, it starts instantly, but there is a lag of unpredictable length between states on numbers five, six, and seven. Slides two and three put the lag at the beginning, then after the sorting is done, the change between states in instantaneous. The lag in slide two is slightly unpredictable, but slide three is consistent.

Don't try to put these slides together in one project, because they all use the same variables, and won't play nicely together.

Ultimately, as you add more options for the states, the lag will get longer. Right now, I think slide two is the optimal option, but if you had more options (say, 25), I think slide three's design would make it faster.

If I had more states than seven, I probably would use js, but here are three options proving it can be done with only SL triggers.