Wave

What Is Going on Inside Their Head: the Pokémon Emerald Random Number Generator

Forbidden Tempura

In Pokémon Emerald, there are several random number generators. The main one, pp_rand(), uses the following generator:

seed = (1103515245 * seed + 24691) as u32
return (seed >> 16) as u16

Where do these constants come from?

The 1103515245 constant is easily explained: It is what ISO/IEC 9899 in all editions provides as an example for how to implement rand(), which itself traces back to 70s UNIX libc rand.c. That function returns a signed 16-bit integer with RAND_MAX == 32767.

Game Freak, however, wanted to have an unsigned 16-bit integer. Therefore, they doubled RAND_MAX to be 65535 instead of 32767. Unsure if this was safe, they also doubled the increment from 12345 to 24690 and added 1 to make sure it was relatively prime to 1103515245, as evidenced by the following comment in calctool.c:

// 12345*2+1 (RAND_MAX=32727の時に12345なら65535の時は倍必要なのではないか?テスト)

In other words, Game Freak was unsure if they also needed to double the increment when doubling RAND_MAX, displaying a failure to understand the theory of the algorithm they were employing. They did understand enough theory to realize that the multiplier is the most important part but then failed to see it through to the very end: As noted by Knuth in The Art of Computer Programming, vol. 2, the only thing that matters is that the multiplier and the increment are relatively prime. At least their change did not make it any worse. They also note that this is a test, yet it was evidently shipped in production.

Incidentally, 1103515245 is a terrible multiplier (K. Entacher, “A collection of selected pseudorandom number generators with linear structures”, Technical report series, ACPC - Austrian Center for Parallel Computation, August 1997).

About the Author

Forbidden Tempura

I am good at being angry about video games.

Mia Rose WinterReviewer

This might also interest you

Settling the debate once and for all: Is Shedinja legal in a Nuzlocke ruleset for Pokémon Emerald?

Forbidden Tempura 3/9/2026

Context What is a Nuzlocke? To set the stage, let's first provide some context to the curious-but-unfamiliar reader as is tradition in essays that portray niche topics that are only ever read by the curious-but-definitely-familiar reader. The “Nuzlocke” ruleset refers to a particular set of rules to create a self-imposed challenge in Pokémon games. These go back to a web comic called Nuzlocke (content warning: swearing, intentional misgendering), later renamed to Pokémon: Hard Mode to differentiate them from other web comics now hosted on the site called Nuzlocke. The original Nuzlocke challenge had two rules written exactly as follows: > release a pokemon if it faints > have to catch the 1st pokemon in each area and nothing else Subsequently, internet autists did what internet autists did best and tried this kind of challenge for their own. Today, you can find a sprawling set of rulesets all derived therefrom. Out of these, I only would like to examine one more: du

Word of mouth in the age of the ad-driven internet

Sara Gerretsen 12/28/2025

If you're my age or older, you probably knew the era where google was actual magic. No matter what you wanted to find, it was there at your fingertips. No matter how specialised or generic, you could find it, if not in one search, then definitely in two. But none of that exists any more. Profit incentives pulled the search engine owners' interests and those of the engine's users apart. Two searches make more money than one. And the advertising model is showing cracks big enough to spook the industry to the next false promise of infinite growth. Now the users of search engines are left with half-functioning and intentionally dysfunctional products. With very little sign it'll improve soon. A problem analysis What does a search engine give the user. Answers to questions yes, but more importantly, a way to discover the internet. The Pre-AI Problem A simple thought experiment, how would you browse the internet without a search engine? What if google, bing, yahoo, kagi, searx and all the me

OtherOpinion

The Quest for Ethical AI: Actually saving time with generated commit message bodies

Mia Rose Winter 11/11/2025

The Total Hatred For AI in Tech If you have existed on the planet earth in the last 36 months you have been undoubtedly been exposed to a slew of AI tools and integrations, half of which are questionably executed and the other half is questionable if it even is AI. With all of that, coming right off of the crypto boom especially the tech-savvy have immediately questioned this hype and over the months grew to hate it with a fury. I do not except myself from that, I was there. For the first months what I previously followed as promising new tech got turned on its head overnight by capitalist pieces of shit at openAI and friends and completely soured my mood for anything that has proclaimed itself AI, and I myself got caught in the rumor hate mill: AI uses 200 quadrillion times more power than a google search, AI uses oceans of water, we need to double data centers because of AI, AI will kill us all, AI stolen my bicycle. As I do not like blindly hating and I also started to distrust how

AITutorial
Powered by Wave