Random Number Generation
This is an exhaustive list of all 212 instances of the RNG routine being called.
I've done my best to document exactly what each call is for, but there are probably a couple mistakes. There are also a couple places where I just gave up, because the code is difficult to follow without much pay off. If I have a reason to investigate those calls in the future, I'll update this page then.
Sprites
- Sparkles
- Used twice to generate coordinate offsets for non-descript, general sprite usage (4 possible values each, indexing a table).
- Used twice to generate coordinate offsets for frozen sprites (4 possible values each, indexing a table).
- Boss death
- Used twice to generate coordinate offsets for explosions (8 possible values each, indexing a table).
- Guards
- Movement timer (40–104 frames).
- Direction to face (4 possible values).
- When swords collide, called once to produce a value 0–7 to index a table for guard recoil timer. Called again to produce another value 0–7 to index a table for Link's recoil timer.
- Weak guards
- Starting direction for weak soldiers (4 possible values).
- Movement timer (48–112 frames).
- Direction to turn for next movement.
- Spear guard
- How long to wait before walking/stopping (80–208 frames).
- Direction to face (4 possible values).
- Flopping fish
- Spawn a fish when non-fish sprites land in water (1/2 chance).
- Pointless call that ticks the RNG but doesn't use the value, when a fish is spawned from tossing sprites.
- Speed on Z-axis (16–32).
- Speed along X- and Y-axis (8 possibilities, indexing a table).
- Lanmolas
- Randomizes the animation graphic of debris (2 possible values).
- Choose starting Y-coordinate (8 possible values to index a table)
- Choose starting X-coordinate (8 possible values to index a table)
- Choose target Y-coordinate (8 possible values to index a table)
- Choose target X-coordinate (8 possible values to index a table)
- Vitreous
- Random value for small eyeballs' animation timers on spawn.
- Choose next eyeball to activate (16 possible values to index a table).
- Starting seed for lightning (8 possible values).
- Arrghus
- Number of frames to wobble in phase 1 (48–112 frames).
- Initial value of animation timer of puffs.
- Agahnim
- Random timer for debrish on crashing to Ganon (48–80 frames).
- Choose next warp (16 possible values, indexing a table).
- Spawn blue ball (1/2 chance).
- Apples
- Number of apples to spawn (2–5)
- Called twice to determine a landing spot.
- Archery game guy
- Animation timer on spawn.
- Bari
- Change direction of movement (1/4 chance).
- Begin electrocution (1/2 chance).
- Timer before electrocution rolls (128–192 frames)
- Bees (wtf all this nonsense)
- Called twice to produce a speed on each axis when spawning bees from a bonk (8 possible values each, indexing a table).
- Called twice to produce a speed on each axis when spawning bees from a bottle (8 possible values each, indexing a table).
- Called twice to produce a speed on each axis when spawning the good bee from his statue (8 possible values each, indexing a table).
- Called twice to help normal bees find a target (4 possible values each, indexing a table).
- Called twice to help good bees find a target (4 possible values each, indexing a table).
- Called twice to help player bees find a target (4 possible values each, indexing a table).
- Popo
- Movement timer (128–192 frames).
- Random speed (16 possible values, indexing a table).
- Bottle vendor
- Controls animation reset (1/256 chance)
- Boulders
- Location along X-axis to spawn (64–192 pixels from left side of screen).
- Bounce left or right (50:50).
- Pink ball guy
- Low byte of X-coordinate target.
- Low byte of Y-coordinate target.
- Recoil speed on Z-axis when kicked by bully (0–15).
- Buzzblob
- Selects new direction of movement (8 possible values, indexing a table).
- Chain chomp
- Idle bobbing timer (16–48 frames).
- Movements while bobbing around (16 possible values, indexing a table).
- Direction for lunging (16 possible values, indexing a table). Except, it's overridden; see next item.
- Decide whether to lunge at Link or at a random target (0 chance of success). This never happens, so they only ever lunge at Link.
- Cucco
- Direction to move in (16 possible values, indexing a table).
- Movement timer (16–48 frames).
- Sturm!: Single call reused to choose which part of the screen the cucco enters from (1/2 chance per axis), its starting position on the other axis, and which edge it enters through on the axis chosen earlier.
- Crab
- Movement timer (32–96 frames). The timer is then masked to choose a number 0–3 to index a table for movement speed.
- Crystal switch
- Offset of sparkle from switch on Y-axis (0–7 pixels). The X-axis offset is not random; it is a frame rule.
- Deadrock
- Movement timer (32–64 frames).
- Direction of movement (4 possibilities).
- Digging game guy
- Prize to give (8 possibilities). 3 of these roll nothing as a prize.
- Second roll to obtain heart piece (1/4 chance). Failure results in nothing.
- Drunkard in pub
- Reset animation timer (1/256 chance).
- Eyegore
- Movement timer (4 possibilities, indexing a table).
- Fairies
- Target X-coordinate.
- Target Y-coordinate.
- Altitude control (1/2 chance to move up or down).
- Speed on spawn.
- Big fairies
- Used twice to generate coordinate offsets for sparkles (4 possible values each, indexing a table).
- Used twice to generate coordinate offsets for sparkles (4 possible values each, indexing a table). Except this entry is for the fairy queens.
- Granting luck level (4 possibilities, indexing a table). 25% good luck; 25% bad luck; 50% chance no luck.
- Fortune teller
- Choose new fortune in Light World (4 possibilites).
- Choose new fortune in Dark World (4 possibilites).
- Freezor
- Offset on X- and Y-axes of sparkles (8 possibilities, indexing a table).
- Ganon
- Warp (1/2 chance; 99/100 chance when on good pace).
- Warp location (4 possibilities, combined with current position, indexing a table).
- Moldorm
- Direction to turn in (1/2 for each).
- Movement timer (32–64 frames).
- Spinning timer (8–24 frames).
- Gibdo
- Movement timer (48–80 frames).
- Gibo
- Speed along X- and Y-axes (8 possibilities, indexing a table).
- Movement timer (32–64 frames).
- Catfish
- Spawn fireball or bomb if quake is owned (1/2 chance).
- Helmasaur
- Movement along X- and Y-axes (8 possibilities, indexing a table).
- First fireball to split.
- Spit fireball (1/2 chance).
- Hinox
- Change direction or not (1/4 chance).
- New direction (8 possibilites but it's also convoluted and based on current direction).
- Movement timer (96–160 frames).
- Hover
- Movement timer (12–28 frames).
- Keese
- Increment a step counter for movement (1/2 chance). This causes keese to go randomly to the next or previous step of movement (16 possible movements).
- Kholdstare
- Movement timer for moving faster (32–96 frames).
- Movement timer for moving slower (96–160 frames).
- Direction along X- and Y- axes (4 possible values, indexing a table). Value reused to decide if Link should be targetted (1/8 chance).
- Offset on Y-axis of poofy colors (8 possible values, indexing a table).
- Offset on X-axis of poofy colors (8 possible values, indexing a table).
- Direction to split ice balls (1/2 chance cardinal or diagonal).
- Kiki
- Velocity on Z-axis when running away (16–31).
- Velocity on Z-axis when jumping on POD (16–32). Yes, these are different ranges.
- Kodongo
- New direction (4 possiblities). If the direction collides with a wall, they will choose the next direction. If all 4 directions are blocked, this will hardlock the game in an infinite loop.
- Breathe fire (1/4 chance), but only on certain coordinates.
- Kyameron
- Respawn timer (96–160 frames).
- X-coordinate offset of sparkle (−4–11 pixels).
- Y-coordinate offset of sparkle (−4–11 pixels).
- Leever
- Movement timer (160–224 frames).
- Movement timer (64–96 frames).
- Lightning
- Path seeding (8 possible values).
- Lynel
- Fireball delay timer (16–32 frames).
- Tablet
- X-coordinate of debris.
- Y-coordinate of debris.
- Moblin
- Movement timer (4 possible values, indexing a table).
- Direction to walk (continue same way or next option). This one is kinda weird.
- Mini moldorm
- Change direction of rotation (1/2 chance).
- Direction to turn when starting a new movement (1/2 chance each).
- Movement timer (32–64 frames).
- Another movement timer (8–24 frames).
- Mothula
- Speed along X- and Y-axes (8 possible values, indexing a table).
- Movement timer (64–96 frames).
- Beam delay (64–96 frames).
- Spike block to bring to life. The first 2 block indices are twice as common as the rest.
- Direction of floor (4 possible values).
- Time until floor changes directions (128‐256 frames).
- Octorok
- Movement timer (48–112 frames). Timer reused to choose direction.
- Movement timer initial value (0–127 frames).
- Pengator
- Offset on X-axis of sparkles (4 possible values, indexing a table, with intricacies for separate movement directions).
- Offset on Y-axis of sparkles (4 possible values, indexing a table, with intricacies for separate movement directions).
- Pikit
- Speed along X- and Y-axes (4 possible values, indexing a table).
- Speed along Z-axis (19–27).
- Item to attempt theft of (4 possibilities).
- Pirogusu
- Direction change (is an ugly table indexing)
- Splash X-axis offset (4 possible values, indexing a table).
- Splash Y-axis offset (4 possible values, indexing a table).
- Time until next spawn (96–127 frames).
- Poe
- Modify Y-direction based on Link's relative location (1/4 chance).
- Actually modify Y-direction (2 possible values).
- Movement timer (16–24 frames).
- Pokey
- Starting direction (4 possibilities, indexing a table).
- Bird
- Speed on Z-axis when spawned (−16–15).
- Rat
- New direction (4 possibilities). Value reused for movement timer (64–192 frames).
- Ropa
- Snake
- Direction to move. Value reused for movement timer (64–192 frames).
- Hoarder
- Speed along X- and Y-axes (4 possible values, indexing a table).
- Trinexx
- Offset on X-axis of explosion (8 possible values, indexing a table).
- Offset on Y-axis of explosion (8 possible values, indexing a table).
- Pick next movement speed (3/4 slow, 1/4 fast).
- Pick the next location to move to (4 possible values, indexing a table; if the same as current location, redo next frame).
- Roll of 0–7 to choose one of 5 side head positions. Rolling current index or indices 6/7 skips the frame.
- If side head is currently at position index 1, 50% to breathe, unless the main body is moving.
- Side head think timer after moving (0–15 frames).
- Used twice to generate coordinate offsets for breath garnish (16 possible values each).
- Sluggula
- Movement timer (32–64 frames). Value reused to set direction (4 possible values).
- Poop bombs (1/2 chance).
- Snapdragon
- Movement timer (4 possible values, indexing a table). Pointless masks higher bits then shifts right. Why?
- Direction to move (4 possible values).
- Stalfos and Zazaks
- Movement timer (4 possible values, indexing a table).
- Next direction to move.
- Stalfos Knight
- When to jump calculation. I don't get it 100% yet.
- Action after recovering (1/2 chance to celebrate).
- Hint NPCs
- Reset animation timer (1/256 chance).
- Swamola
- Direction to move when emerging (8 possible values, indexing a table).
- Direction to move when submerging (8 possible values, indexing a table).
- Tektite
- Movement timer (48–112 frames).
- Speed on Z-axis (24–32).
- Direction to move (4 possible values, indexing a table).
- Another movement timer (72–136 frames).
- Terrorpin
- Movement timer (32–64 frames).
- Thief
- Item to attempt to steal (4 possible values).
- Firesnake
- Witch
- Bunny
- Offset on X- and Y-axis from original spawn point (4 possible values, indexing a table).
- Wizzrobe
- Teleport timer (32–64 frames).
- Blobs
- Movement timer (96–159 frames).
- Movement timer again (64–96 frames).
- Movement timer stop point (16–31 frames).
- For endless spawns: initial movement timer (16–31 frames).
- Zora
- Relative X-position from initial spawn to resurface (8 possible values, indexing a table).
- Relative Y-position from initial spawn to resurface (8 possible values, indexing a table).
- King Zora
- Speed on Z-axis of flippers (24–40). The exact implementation suggests a different routine was being used at some point in development, possibly very early on in this case.
- Zoro
- X-axis offset of spawn (8 possible values, indexing a table).
- Animation timer start point.
- Cannonballs
- Shooter activated for full room shooters (15 possible values, indexing a table).
- Position of next small ball (1/2 chance left or right).
- Zirro
- Movement timer before direction change (32–63 frames). Value reused immediately for speed on both axes (8 possible values, indexing a table).
- Generates a number that is masked with a value corresponding to prize packs. Results in 1/2 for most prize packs, except the magic prize pack, which is 1/1.
- Completely unreachable code
- Movement timer
- Another movement timer
Other
- Ancilla sparkles
- Generate coordinate offsets for general use sparkles (each nibble used separately to create a value 0–15 on each axis with one output). This routine is called by various ancillae, such as the red boomerang, opening Ganon's Tower (in addition to its own RNG), and crystals. It is also used by Link when sword is charging and the crystal maiden sprites.
- Generate coordinate offsets for crystal sparkles when opening Ganon's Tower (each nibble used separately to create a value 0–15 on each axis with one output).
- Generate coordinate offsets for sword charge sparkles (each nibble used separately to create a value 0–15 on each axis with one output). Distinct from above routine.
- Generate coordinate offsets for silver arrow sparkles (each nibble used separately to create a value 0–15 on each axis with one output).
- Chest game
- Generate prize for low-stakes chest game (16 possible values).
- Generate prize for high-stakes chest game (16 possible values).
- Generate prize for heart-piece chest game (8 possible values).
- Bush/Rock prizes
- Actually try to spawn something when outdoors (1/2 chance).
- Choose prize for fairy/heart pack bushes (4 possible values).
- Success for specific overworld secrets; e.g. bomb bushes (1/2 chance).
- Credits
- Used twice to generate coordinate offsets of big fairy sparkles (8 possible values, indexing a table).