Atlasプレビュー
しくみ

乱数とその調整

第3世代の乱数は計算で決まる数列。予測でき、狙える。

Generation 3: a sequence, not a die

The game keeps a 32-bit number, the seed. On every draw it replaces it with seed × 1,103,515,245 + 24,691 (keeping 32 bits) and returns the top 16 bits. The result depends only on the previous seed: the sequence is always the same.

And the game draws one number every displayed frame, even when nothing happens — about 59.73 times per second on a Game Boy Advance.

Sources : pokeemerald include/random.h : ISO_RANDOMIZE1 ; src/random.c : Random ; src/main.c : VBlankIntr (Random() à chaque image)

Where the sequence starts

Ruby and Sapphire set the seed at boot from the cartridge clock (minutes elapsed, folded to 16 bits). In Emerald that call only exists in the fixed build of the code: the retail game always boots with seed 0.

That is what makes Emerald so predictable: after a reset, the same frame always gives the same draw.

Sources : pokeruby src/main.c : SeedRngWithRtc ; pokeemerald src/main.c : SeedRngWithRtc sous #ifdef BUGFIX

Aiming at a frame: manipulation

A wild Pokémon in Emerald is born in a few consecutive draws: one for the nature, then two per personality-value attempt until it matches that nature, then two for the six IVs. So everything is fixed by the seed at the moment the battle starts.

The tool below walks the frames from the starting seed and shows those where that Pokémon would be shiny for your IDs. Manipulating means triggering the encounter on that very frame. (Simple case: no Synchronize, no Cute Charm, outside the Safari Zone. Other draws come first — species and level — which must be counted in practice.)

Sources : pokeemerald src/wild_encounter.c : CreateWildMon, PickWildMonNature ; src/pokemon.c : CreateMonWithNature, CreateBoxMon (Random32, deux Random() pour les IV)

Generations 1 and 2: hardware randomness

On Game Boy there is no formula: the game keeps two bytes and, on each call, adds to the first and subtracts from the second the value of a console counter (the DIV register, which ticks 16,384 times per second). The same update runs every frame.

The result therefore depends on the exact elapsed time: it can be predicted by reading the state, but not with a simple formula.

Sources : pokered engine/math/random.asm : Random_ ; pokecrystal home/random.asm : Random