Shuffle
RANDOMNESS
Loading audio…
Press play to listen along. The line being read lights up as you go.
Show full transcript
Loading transcript…
In the corner of the CodeRealm workshop sat a covered cup, and at that exact moment it was doing something no one in the room could predict. Loop had it on the bench before a class of squinting kids — a plain lidded tumbler that, when shaken, made a dry, rattling music: a whole crowd of small numbered tokens knocking together in the dark. "This is Shuffle. Randomness. Watch closely, because I promise I don't know what happens next either." He tipped the cup; a single token slid out and rolled to a stop. 4. He scooped it back, capped, shook — that rattling music — and drew again: 1. Then 6. Then 1 a second time. A kid leaned forward, frowning. "Do it once more." 3. The kid sat back, a little defeated and a little delighted, because they'd genuinely been trying to guess and there had been nothing to grab onto — no pattern, no rhythm, no next-in-line. "That's the whole job," Loop said. "When a program needs something you can't guess ahead of time — a dice roll, a random enemy, a shuffled quiz — you draw from Shuffle. A value nobody can see coming. Not the workshop, not you, not even me."
Loop noticed a kid at the back who wasn't laughing. This kid had built a guessing game the week before, and it had failed in the most boring way possible: every time you played, the "secret" number was 7. Always 7. The first player found it in one run, told everyone, and the game was dead. "It wasn't broken," the kid said, miserable. "It ran perfectly. It was just... the same. Every time. I made a game that couldn't surprise anybody." Loop pulled the cup over. "You didn't need a bigger machine. You needed one that forgets. Watch." He shook and drew — 5 — capped, shook, drew again — 2. "It doesn't remember the last draw. It has no favourite number. There's no seven waiting in there for you to trip over. Every draw is independent — fresh, on its own." The kid picked up the cup, shook, drew 6, shook, drew 1 — and something loosened in their chest, the flat stuck feeling of the same, the same, the same lifting off, replaced by the small rising fizz of I don't know what's next. "That jumpy, don't-know feeling," Loop said gently, "is the thing your game was missing. Not a bug. A surprise."
The kid brought their game back the next morning and set the cup on the bench like it belonged there. "I want to build it right this time." Loop didn't ask them to prove anything; he asked one question. "What does randomness give a program?" The kid didn't answer with words. They wired Shuffle into the guess-a-number game so each round drew a fresh secret token from 1 to 9 — and made Loop play it. Loop guessed 4; wrong, it was 8. Reset. Loop guessed 8 on purpose this time, grinning; wrong again, it was 2. "You can't cheat it," the kid said, "because I don't even know what it'll draw. It picks fresh, every round, from the cup." Loop played three more rounds, lost every guess, and by the end was laughing. "You belong here," he said, and set the cup back beside the game like it had always lived there.
By afternoon the kid had a little crowd, and one wanted a game of their own. "I need dice for a board game. But how does a cup roll a six?" The kid who now understood Shuffle pulled the cup over. "You put six tokens in — 1 to 6. Shake." Rattle. "Draw." 3. "There's your roll. Want a coin flip? Two tokens. Want a random cheer? Fill a list with phrases, shuffle, draw one. Same idea every time: shake, draw, get a fresh one." The new kid dropped in six tokens and drew. 5. Then 5 again. "Wait — two fives! Is it stuck? Am I due for a low one now?" The first kid shook their head, remembering exactly how Loop had said it. "That's the honest part, and it's the trap almost everyone falls into — the gambler's fallacy. It doesn't keep score. Two fives in a row doesn't make the next draw any less likely to be a five. The cup has no memory and no fairness-debt — it isn't 'saving up' a low number for you. Every draw is independent, completely on its own." The new kid drew again, half-braced for a five, and got 1, and the whole small crowd let out a whoa.
When the workshop emptied, the first kid stayed with the cup, running their fixed game one more time, alone. They'd wired it to draw a fresh secret number and a random cheer and shuffle the questions into a new order. Run: 3, a chirped Nice one!, questions in one order. Run again: a different secret, a different cheer, a different order entirely. Same exact code. Brand-new run. And then it happened — the game surprised them, its own builder — and they laughed out loud in the empty room. The cup sat on the bench, lid on, tokens hidden, quietly ready for the next shake. It wasn't thinking. It wasn't feeling lucky. It was just a cup of tokens you shook and drew from, fresh and independent every time. But the kid, watching a thing they'd made astonish the one who made it, felt the brightest, jumpiest kind of happy — the delight of not knowing what comes next, of building something alive enough to still amaze its author. They shook the cup once more before they left, just to feel that small rising fizz, drew a 6, and grinned all the way out the door.
Hear it as an audio drama
A short play starring Shuffle, from CodeRealm. Different voices, same idea. Listen any time after you read.
Loading audio…
Read the drama script
- Narrator: From Spark and Anvil and CodeRealm — this is Shuffle, in chapter 1 of the CodeRealm cast.
- Narrator: This drama uses an AI-generated voice. Voiced via Gemini 2.5.
- Narrator: In the corner of the workshop sits a covered cup — a plain lidded tumbler that, when shaken, makes a dry rattling music: a crowd of small numbered tokens knocking together in the dark. This is Shuffle.
- Loop: This is Shuffle. Randomness. Watch closely, because I promise I don't know what happens next either.
- Narrator: Loop tips the cup. A single token slides out. Four. He scoops it back, caps, shakes, draws again. One. Then six. Then one a second time.
- Kid: Do it once more.
- Narrator: Three. The kid sits back, a little defeated and a little delighted — genuinely trying to guess, and nothing to grab onto. No pattern, no rhythm, no next-in-line.
- Loop: That's the whole job. When a program needs something you can't guess ahead of time — a dice roll, a random enemy, a shuffled quiz — you draw from Shuffle. A value nobody can see coming. Not the workshop, not you, not even me.
- Narrator: One kid at the back wasn't laughing. Their guessing game had failed in the most boring way: every time you played, the secret number was seven. Always seven.
- Kid: It wasn't broken. It ran perfectly. It was just the same, every time. I made a game that couldn't surprise anybody.
- Loop: You didn't need a bigger machine. You needed one that forgets. It doesn't remember the last draw. It has no favorite number. There's no seven waiting in there for you to trip over. Every draw is independent — fresh, on its own.
- Narrator: The kid shook the cup, drew six, shook, drew one — and something loosened in their chest, the flat stuck feeling of the-same-the-same-the-same lifting off, replaced by the small rising fizz of I-don't-know-what's-next.
- Narrator: By afternoon a new kid wanted dice for a board game, and dropped in six tokens.
- Kid: Wait — two fives! Is it stuck? Am I due for a low one now?
- Loop: That's the trap almost everyone falls into — the gambler's fallacy. It doesn't keep score. Two fives in a row doesn't make the next draw any less likely to be a five. The cup has no memory and no fairness-debt. It isn't saving up a low number for you. Every draw is independent, completely on its own.
- Narrator: The new kid drew again, half-braced for a five, and got one, and the whole small crowd let out a whoa.
- Narrator: When the workshop emptied, the first kid ran their fixed game one more time, alone — a fresh secret number, a random cheer, the questions in a new order. Same exact code, brand-new run. And then it happened: the game surprised its own builder. They laughed out loud in the empty room, shook the cup once more just to feel that fizz, drew a six, and grinned all the way out the door.
- Narrator: You've been listening to a Spark and Anvil chapter, written by the Spark and Anvil writing team for ages 9 to 14.
- Narrator: Apps stay free forever.
- Narrator: Curriculum aligned to Computer Science Teachers Association standards.
- Narrator: Released under Creative Commons BY-NC-SA 4.0 for educational reuse. Visit Spark and Anvil for the full transcript.
The CodeRealm ensemble
Shuffle is one of the friends in CodeRealm. Each friend shows you one idea by how they act; meet them all and you have the whole subject.
-
Stash
Variable / storage — the labeled box that holds a value until you call for it
-
Fork
Conditional / branching — chooses a path based on what's true right now
-
Trek
Loop / iteration — keeps going around until the work is done
-
Module
Function / encapsulation — does one job well and can be called anywhere
-
Glitch
Debugging / inspection — finds bugs gently, never shaming; 'there's always a reason'
-
Order
Sequence / syntax — reminds you that order matters in code
-
Row
A list: many values lined up in a numbered row, so you can grab item number three instantly or walk through them one by one.
-
Port
Input and output: the doorway that brings information in from the world (a key press, a sensor) and sends results back out.
-
Ping
An event: a waiting bell that does nothing until its trigger happens, then runs its code the instant it is struck.