The randomize line is all about probabilities – the odds of a bet, the likeliness for rain, or simply the chance to win.
That means randomize choses one line out of a number of lines, each with its own predefined likeliness. It affects all kinds of lines, e.g. paragraphs, links, shuffle lines etc.
The randomize line is the pick line's older brother. It can do everything the pick line can. But the pick line makes it easier to achieve the kind of randomization that works like a lottery. If you are new to both, learn how to use the pick line first.
A simple randomize line starts with a :RANDOMIZE: tag followed by two numbers. Both numbers represent probabilities. The first number stands for the first line after the randomize line, the second number for the second.
You decided to enter into Alfonsos pizza eating contest and challenge the favorite: Francesca.
After fifteen minutes of berserk style face-stuffing we have a result:
:RANDOMIZE: 60 40
Francesca won. She's a real pro. There's no shame in being second to her.
You won due to sheer determination and willpower.
:LINK: Go again | pizza eating contest
In this example the randomize line chooses one out of the two lines that immediately follow it:
- Line 5 will be chosen 60 percent of the time.
- Line 6 will be chosen 40 percent of the time.
That means, it is a little more likely for Francesca to win the contest. If you go again, the odds remain the same.
Workflow tip: In this example, the two probabilities add up to 100, which means they represent percentages. If percent values make sense to you, stick to them.
However, you could use numbers of any scale to reflect the proportion between choices. The randomize line above would work just the same if it were written like this: :RANDOMIZE: 3 2.
Practice tip: Write another result in a new line below line 6, add a third number to the randomize line, hit update and see what happens.
Sometimes you want to randomly choose a group of lines rather than a single line. In these cases you can specify the number of lines in each group.
You check the weather forecast. It says:
:RANDOMIZE: 80|2 20|2
"Today will be sunny. An awesome day to go out and get some pizza."
"Great," you think on your way to Francesca's.
"Big storm ahead! You should have your pizza delivered."
You punch in Alfonso's number quickly from memory.
:LINK: Next day|weather
Here, the randomize line chooses one of two groups. Each group has two lines:
- Lines 4 and 5 will be chosen with a probability of 80 percent.
- Lines 6 and 7 will be chosen with a probability of 20 percent.
Remember the example in the first section? Like the one in this section it can be written with line numbers: :RANDOMIZE: 60|1 40|1. However, if a group has only one line, you can omit the line number.
Workflow tip: You can put the groups in parentheses: :RANDOMIZE: (80|2) (20|2). That could improve the legibility of your randomize line.
Choose something or nothing
There might be situations where you want 'nothing' to be a possible choice. You achieve that by defining a group with 0 lines.
Just like every Wednesday you order your favorite pizza.
:RANDOMIZE: (25|1) (75|0)
But today must be your lucky day! You get a free soda.
:LINK: Next week|lucky day
In this randomize line two groups are defined. The first group has one line and a probability of 25 percent of being chosen.
The second group is chosen 75 percent of the time. However, when randomize chooses it, no text gets displayed, because this group has zero lines. In other words, it is empty.
Return to a randomize line
In non-linear texts it is likely for readers to make decisions that will lead them back to a card they have already visited.
If a randomize line happens to be inside such a card, it will choose again.
Keep or lose a chosen line
Imagine the following situation: You enter a room with 22 people and ask for their birthdays. There is a 50 percent chance that two people in that room share the same birthday. This probability will be the same when you enter another room with a different group.
Whether or not two people actually shared a birthday in the first room does not influence the probability of two people sharing their birthday in the second room.
This is how a randomize line works. No matter how often it chooses, one choice does not impact the next. All choices (and their probabilities) will be available even after they have been chosen.
However, if you want to change this behavior, randomize knows a special keyword: lose.
After a long hard day you enter Francesca's, shaking from exhaustion and hunger.
:RANDOMIZE: (55|2) (30|2|lose) (15|2)
"I'd like a large pie, please," you stutter.
Francesca looks at you worried. "Here, have a seat. Your pizza is coming right up."
You trip over the clothes tree Francesca's keeps near the entrance. It falls over with a loud bang. Everyone in the shop looks at you.
"You need a large pizza. And quickly," Francesca declares as she accompanies you to a nearby table. "And I'll move that darn stand."
"Hey, your pie is already waiting for you!"
Overwhelmed you sit down, tears of joy fill your eyes. Francesca is the best.
:LINK: Fast forward to next Monday|tough day
In this example, three situations can occur, each with a different probability. However, once situation 2 has happened, it will not happen again, because you cannot trip over the clothes tree after Francesca has moved it.
In other words, there are three groups defined. When the randomize lines chooses group 1 or 3 they remain available for next time.
Group 2, on the other hand, has the lose keyword. Once this group has been chosen it gets discarded. It won't be available when this randomize line chooses again.
Practice tip: Click the forward link a few times after group 2 has been chosen. You'll see, it won't be chosen again. Now remove the lose keyword, hit update, click the link a few times and see how the original behavior has changed.
Workflow tip: Groups 1 and 3 also have a keyword, but it is implicit: keep. You could write the randomize line above like this :RANDOMIZE: (55|2|keep) (30|2|lose) (15|2|keep) and it would work the same way. Use this option to make your source text easier to understand.
Restart after exhausting all choices
You can add the lose keyword to every group in a randomize line. Eventually, that will lead to a situation where all groups have been chosen once and none are left.
In that case the randomize line will simply start over. All options become available again.
:RANDOMIZE: (25|2|lose) (60|2|lose) (15|1|lose)
As you enter Alfonso's shop you realize that the place is deserted. Must be your lucky day.
:LINK:"Alfonso, one pizza aglio por favor!"|reaction
Alfonso's is so crowded that you have to wait outside. After 15 minutes you manage to cram yourself inside.
:LINK:"Alfonso, can you hear me? I'd like a piccante, please,"|reaction:: you yell while wedged between the door and someone's ample buttocks.
Alfonso's is closed today. :LINK: Time to go home and cry until the next evening.|time for dinner
"Coming up," Alfonso replies cheerfully. He's in a good mood.
:LINK: Next evening|time for dinner
When you click on the links you will encounter all three situations, most likely in the order of their probabilities. After each situation has occured once, they all become available again.
Stop after exhausting all choices
In some situations it might not make any sense to start over when all groups have been chosen once. Rather, something should suggest that there are no more options left.
For that you can define a group in your randomize line that has a special keyword: after.
"Today is the day you've been waiting for, my friend," Alfonso burst out as you enter. "Pizza raffle day. Just pick a tick! Each is a winner!"
:LINK: You try your luck|your-result
:CARD: your result
:RANDOMIZE: (65|1|lose) (35|3|lose) (1|after)
Your ticket says you win: a delicious pizza salami! Alfonso gets to work immediately.
Your ticket says you win: a place in Alfonso's hall of happiest customers!
"Say cheese!" Alfonso snaps a pic of you without further warning. You look, well, memorable.
"Just perfect for my wall of friends over there," chirps Alfonso.
"Sorry, the raffle is over. But at Alfonso's you always win – a big smile from me! You're so lucky," Alfonso exclaims grinning broadly.
:LINK: "Can I draw again?"|your result
In this raffle you can draw two winning tickets. Once they have been drawn the raffle is officially over. If you keep asking for a ticket, Alfonso gives you the same answer each time.
This randomize line is defined with three groups. The first two are the actual choices. They have the lose keyword, so they get discarded after being chosen once. Consequently, after choosing two times, there are no choices left.
The third group is different: It has the after keyword and no probability. It does not get chosen like the first two groups. But as soon as the first two groups are discarded this group gets displayed each time.
The after group does not need a probability, because the randomize line does not choose it based on probability.
Workflow tip: If the after group has 0 lines, nothing gets displayed once randomize has run out of options.