Randomizing What is Displayed🔗
There comes a time in every GT programmer's life (that's you by the way; you're becoming a GT programmer as you read this!) when you want to make a program vary each time it is run. The most basic way to accomplish this is with the *randomize
keyword. (Note: if you are actually running an experiment or need to keep randomized groups of equal participant size, then the *experiment
keyword may be a better fit for you.)
Let's take a look at *randomize
:
*randomize
You SUCK!
Go AWAY!
You couldn't beat YOURSELF in a fight!
This is a great way to sling a randomly selected insult at the unsuspecting user. In this case, the user will see one (and only one) of the three insults.
What if you wanted to give them a double whammy, though? The old one-two punch. You'd do it like this:
*randomize: 2
You SUCK!
Go AWAY!
You couldn't beat YOURSELF in a fight!
This means that rather than picking one insult to show, it will show two instead. As it stands, it will pick two different insults (i.e., it selects at random and without reusing each option, so that each option is used at most once).
Randomize All🔗
What if you want to show all of the items, but in a random order? Well, my friend, you're in luck. Just use:
*randomize: all
You SUCK!
Go AWAY!
You couldn't beat YOURSELF in a fight!
Randomizing Every Time🔗
Once a user activates a *randomize
keyword, the program remembers the randomized selection and will re-display it whenever the user passes that same *randomize
again (i.e., if they press the back button or return to it via a *goto
keyword, they will see the same randomized thing they saw the first time). This makes sense, since a lot of the time you don't want the user to realize they're being shown random content.
There's a way to allow a *randomize
keyword to re-randomize *everytime
the user passes it:
*label: beginning
*randomize
*everytime
Starfish
Catfish
Duckfish
*question: Want to see another fish?
Yes
*goto: beginning
No
With the addition of the *everytime
keyword, your randomized content will re-randomize each time the user sees it. This will pave the way for new fishes for your user to enjoy. Every time.
Note: If you'd like to learn about randomizing answer options within a question, see the *shuffle
keyword.
Embedded Expressions in *randomize
🔗
You can also make the number of randomizations a bit more personal by adding variables or mathematical expressions.
*question: How many appetizers would you like on your menu?
1
2
3
4
*save: number
*randomize: {number}
pickled oysters, macomber turnip remoulade & toast
marinated fennel with feta & preserved lemon
gruyere stuffed black truffle gougères
chicken liver mousse, pickled onions & toast
confit duck leg, beet purée, frisée & walnut brittle
In the above program, the number of appetizers randomly shown will be the same number that the user asked to see.
You can also include mathematical expressions:
*question: How many appetizers would you like on your menu?
1
2
3
4
*save: number
*randomize: {number + 1}
pickled oysters, macomber turnip remoulade & toast
marinated fennel with feta & preserved lemon
gruyere stuffed black truffle gougères
chicken liver mousse, pickled onions & toast
confit duck leg, beet purée, frisée & walnut brittle
Although you asked for {number}, we gave you one bonus!
In this example above, the user will be shown one more appetizer than the one they asked for.
Randomizing a Group of Commands🔗
Let's say you want to randomly show the user not just one command or line of program at a time, but multiple commands or lines of program code grouped together. You can do so by indenting two or more *group
keywords beneath the *randomize
keyword, and by placing your commands or text one indentation further beneath each *group
keyword. Here's an example:
*randomize
*group
Hi!
This is great
*group
Hey!
This is wonderful
In the example above, users will either see "Hi!" with "This is great" beneath it or they will see "Hey!" with "This is wonderful" beneath it. The *group
randomization can get much more complicated than that. You can add sequences of commands, such as questions, as long as they are grouped together by being indented beneath each *group
.
Make Viewing Data Easier by Naming Randomizations🔗
Giving a proper name to each randomization or randomized *group
will greatly ease your ability to analyze the data. While the user won't see the name of the group they were assigned to, you'll be able to quickly see which users got assigned to which group names later on when you're reviewing the results of your program. Take a look at the example.
*randomize
*name: intervention
*group: jump_pushups
Jump up and down 10 times!
Then do 5 pushups.
*group: spin_run
Spin in a circle 5 times!
Then run around for 10 seconds.
Now when viewing the data, you'll see a column called "Randomize (intervention)." Beneath this column, each run will have an entry of "jump_pushups" or "spin_run" depending on whether the user of that run was randomly assigned to the jumping and pushup group or the spinning and running group.
Since *randomize
can choose one or several things (e.g., *randomize: 2
), when it's the case that more than one thing is randomized, the value for each run will be a comma-separated list of the sequence chosen in the order it was chosen (e.g., "spin_run, jump_pushups").
Without adding names to your randomizations, you'll instead see 7-letter codes in the data. You would have to then figure out which randomization was assigned which 7-letter code. This can be tedious and difficult, so it's best to name the randomization and groups when it's important to know which randomization(s) a user received.
Next: Repeating