Randomly allocate values to variables without duplicates (Javascript?)

Hi,

I've been scouring ELH for a solution for a seemingly simple challenge. While I'm not working with playing cards, the analogy applies:

Let's say I have 52 variables for 52 playing cards. Upon launching the Storyline I would like to randomly allocate 52 values to those 52 variables without duplicates:

varCard01 '2ofClubs'
varCard02 'JackofSpades'
varCard03 '3ofSpades'
...etc...

Is there a Javascript (or otherwise) solution for defining strings and populating the variables randomly, without duplicates, upon opening the Storyline?

I have tried achieving this with multiple layers with actions that either allocate, or loop the random if a true/false variable has been set true by a previous layer, but this has proven to be a fool's errand.

 

1 Reply
Walt Hamilton

The general concept is that you start with a (probably ordered) list of the values you want. Then you cycle through the list moving or copying the values to random unpopulated spots in the target variables. This approach prevents duplicates, yet provides random allocation.

It seems to me that it could be done in SL, but would be magnitudes of time faster with js.