# Selecting a variable randomly from "create multiple variables" module?

Hi,
I’m using a google sheet as a calculation engine and want to spread the load across a few different sheets. In module 9, i “set multiple variables” named worker1-3 which contain the sheetID of the google sheets that i want to use as my calc engine.

My question is how do I randomly select one of the 3 variables i created in module 9 down the line in my scenario? Obviously i can choose 1 by just dragging it into the field. But how do i have it populate randomly (or better yet iterate through worker1-x) on each successive scenario run? @JimTheMondayMan you seem to have answered similar questions before, is this a simple thing to get done?

Thanks All

If you create an array instead of named variables, you might be able to use the [random] variable to pick one of the array items. A formula like:

ceil([random]*3) would give you an index number of 1, 2, or 3

L

Then how do i create an array by setting the data somewhere in make? If all else fails, I guess i can create a sheet that has the IDs of the other 3 worker sheets and “get a cell” through make. Just seems like i should be able to set my variables and pick one randomly within make.

If you’re selecting workers, then shouldn’t it be uniform distribution rather than random?

You can use an increment module (setting Reset a value to Never) and the scenario will just keep incrementing the number (variable “i”) by one every time the scenario runs.
You could check that number and take a router accordingly.
If i mod 3 = 0 then that’s worker 1.
If i mod 3 = 1 then that’s worker 2.
if i mod 3 = 2 then that’s worker 3.

using increment for workers.json (14.2 KB)

You don’t need to use the `random` special variable, or `mod` operator, or even know the LENGTH of the array to “calculate” which random item to use.

All you need is the shuffle and first functions to get a random item from an array.

``````{{ first(shuffle( 1.array )) }}
``````

To answer your original question, you first need to build this ARRAY.

You can use the built-in function `add`,

e.g.:

``````{{ add(emptyarray; 9.`Worker 1`; 9.`Worker 2`; 9.`Worker 3`) }}
``````

Then insert it into the array placeholder in the above example:

`{{ first(shuffle(add(emptyarray; 9.`Worker 1`; 9.`Worker 2`; 9.`Worker 3`))) }}`