Random does not mean “take turns”

Programming guides

A random choice can surprise you. It does not promise to take turns, avoid repeats, or make every short sequence look balanced. Rolling a six does not mean the next roll must be something else.

In Pliro, randomInt(1, 6) gives a whole number from one through six, including both ends. This is useful for dice-like experiments and game choices.

Look at a small experiment

If you throw a die twelve times, you might expect roughly two sixes. But a particular set of twelve throws might contain fewer or more. “About two on average” is not a rule requiring exactly two every time.

Pliro uses a calculated, pseudorandom sequence. It comes from a repeatable calculation rather than a physical die. Fresh runs can repeat the same sequence, which helps reproduce a program when testing it. Do not use this educational function to make passwords or secrets.

Count the sixes

# language: en
let sixes = 0
for turn in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]:
    let roll = randomInt(1, 6)
    say roll
    if roll == 6:
        set sixes = sixes + 1
say "Sixes:", sixes

The list gives us twelve turns. Each turn makes one choice and displays it. The if increases the counter only for a six.

Predict, then run

Can we promise exactly two sixes? Can the same number appear twice in a row?

We cannot promise two. Repeated numbers are allowed. The output has twelve roll numbers, each between 1 and 6, followed by a six-count between 0 and 12. Count the displayed sixes yourself and compare that count with the final message.

Your challenge

Change the experiment to a four-sided die. Update the bounds and decide which result to count. Run the same program again and compare the sequences. What would you record to make the experiment reproducible?

A common mistake

Changing the lower bound to zero gives seven possible values: 0 through 6. That is a different game. Also, a short experiment is not enough evidence to declare a random chooser unfair just because its counts are uneven.

Where next?

Random whole numbers · Loops · Testing