- 4
- Posts
- 2
- Years
- Seen Sep 30, 2024
This is a patch that replaces the random number generator used in Emerald with a newer random number generator with higher quality output. The random number generator used is called SFC32.
Care has been taken to ensure that link compatibility, with some minor exceptions, has been maintained with the original game.
Getting started
If you just want to replace the original random number generator, all you need to do is this:
I have tested this with vanilla and the RHH expansion.
Why do this?
Why not just use the Mersenne Twister like the DS games do?
What doesn't work?
What's next?
There are many other functions added in this patch that are not used for better compatibility with other feature branches. If used, these can increase the clarity and performance of your code. They are listed at https://github.com/tertu-m/pokeemerald/blob/random/random.md.
Care has been taken to ensure that link compatibility, with some minor exceptions, has been maintained with the original game.
Getting started
If you just want to replace the original random number generator, all you need to do is this:
Code:
git remote add tertu-m https://github.com/tertu-m/pokeemerald
git pull tertu-m random
make clean
make
I have tested this with vanilla and the RHH expansion.
Why do this?
- Seeding fixes are included.
- The RNG is more fair. For example, every personality value/IV combination is theoretically possible for wild Pokemon now.
- RNG prediction is harder, and existing tools (such as frame lists) don't work because they assume the vanilla game's random number generator is being used.
Why not just use the Mersenne Twister like the DS games do?
- The Mersenne Twister's state is about 2KB. On a machine with as little RAM as the GBA, that's a lot of RAM to burn on one thing. SFC32's state is 16 bytes.
- Every 628th output from the Mersenne Twister takes way longer because the internal shift register has to be updated. Each SFC32 update takes the same amount of time, which is pretty similar to how long the fast Mersenne Twister updates take.
- The output of the Mersenne Twister tests worse statistically than SFC32.
What doesn't work?
- Link battle recording has been disabled. This patch just tells other copies of Emerald that battle recording isn't allowed, which seems to work fine.
What's next?
There are many other functions added in this patch that are not used for better compatibility with other feature branches. If used, these can increase the clarity and performance of your code. They are listed at https://github.com/tertu-m/pokeemerald/blob/random/random.md.
Last edited: