For some time there has been some confusion about the unusual amount of clones when resetting legendarys. It has been speculated that the reason for this is the way the game generates random numbers but, to my knowledge, there has never been a deeper analysis of that matter until now.
Theory
The Pokegames use a linear congruential random number generator with a 32 bit buffer. As with all pseudo random number generators the real series of values is deterministic. So if you know the state you know what the next “random” number will be. Normally this problem is avoided by seeding the the generator. That means the initial random value depends on real time for example.
How Pokegames seed
RSFL seeds based on something in their savegames instantly when you start the game. I currently don’t know what exactly.
DP seeds when you load your game. The seed is based on how long you are in the menu and the current real ds time.
Emerald is different. Emerald never seeds besides one time when you enter your nickname. Normally when loading a game emerald does not seed. The reason why the events in emerald are not completely static is that there is a useless rand call about every 1/60 s.
This is the main reason why I chose Emerald for further examination.
Emeralds initial state is always 0. I implemented my own version of the pokemon random number generator. For reference this is what it looks like
[FONT="]u32 randbuf=0;[/FONT]
[FONT="]u16 pokerand() {[/FONT]
[FONT="] randbuf = (randbuf*0x41C64E6D)+0x6073;[/FONT]
[FONT="] return (randbuf >> 16);[/FONT]
[FONT="]}[/FONT]
Basically you can see randbuf as a recursive series (A_n) with A_0 = 0 and A_n = f(A_(n-1)) (sorry for the crappy formatting it’s a shame that latex is not standart in boards…) the real returned value is always the upper halfword of randbuf.
It should be fairly obvious at this point that after catching the legendary (in my case ho-ho). You can calculate how often pokerand() was called before the Pokemon was generated.
That offers a great advantage because after that you don’t have a cryptic looking pseudorandom number but a plain n. You know that n increases with time in emerald and that it increases faster if your actions require a lot of rand() calls. If you always do the same things you can see n as a time axis with small correction. You can identify one unique Ho-oh with one n. That’s what I do with 70 Ho-oh caught on German emerald.
Results
The results are what I expected but I was a little surprised when I found that all 70 Ho-oh are in the Interval n element [860:980] so even if I catch 1000 Ho-oh’s chances are that I only get like 130 different ones. I expected a kind of Gaussian distribution and well that fits quite nicely if you look at the plot
Here we have the number of Ho-ohs I caught with that n. As you can see the amount of clones I got is really big. The blue line is gaussian fit. The error margins are quite big, but that’s probably because 70 is not enough (but there is no way I’d want to repeat this even more often.
Practical implications
The obvious one would be when reseting legendarys before you run into them take your time. That way n will evolve a little further giving you a bigger interval. And change times. Otherwise you will end up with the same iv distribution very often and thus wasting even more time. In RSFL walk around a little and save like once every 20 attempts so you get a different seed. Only the new games don’t have this problem at all.
Theory
The Pokegames use a linear congruential random number generator with a 32 bit buffer. As with all pseudo random number generators the real series of values is deterministic. So if you know the state you know what the next “random” number will be. Normally this problem is avoided by seeding the the generator. That means the initial random value depends on real time for example.
How Pokegames seed
RSFL seeds based on something in their savegames instantly when you start the game. I currently don’t know what exactly.
DP seeds when you load your game. The seed is based on how long you are in the menu and the current real ds time.
Emerald is different. Emerald never seeds besides one time when you enter your nickname. Normally when loading a game emerald does not seed. The reason why the events in emerald are not completely static is that there is a useless rand call about every 1/60 s.
This is the main reason why I chose Emerald for further examination.
Emeralds initial state is always 0. I implemented my own version of the pokemon random number generator. For reference this is what it looks like
[FONT="]u32 randbuf=0;[/FONT]
[FONT="]u16 pokerand() {[/FONT]
[FONT="] randbuf = (randbuf*0x41C64E6D)+0x6073;[/FONT]
[FONT="] return (randbuf >> 16);[/FONT]
[FONT="]}[/FONT]
Basically you can see randbuf as a recursive series (A_n) with A_0 = 0 and A_n = f(A_(n-1)) (sorry for the crappy formatting it’s a shame that latex is not standart in boards…) the real returned value is always the upper halfword of randbuf.
It should be fairly obvious at this point that after catching the legendary (in my case ho-ho). You can calculate how often pokerand() was called before the Pokemon was generated.
That offers a great advantage because after that you don’t have a cryptic looking pseudorandom number but a plain n. You know that n increases with time in emerald and that it increases faster if your actions require a lot of rand() calls. If you always do the same things you can see n as a time axis with small correction. You can identify one unique Ho-oh with one n. That’s what I do with 70 Ho-oh caught on German emerald.
Results
The results are what I expected but I was a little surprised when I found that all 70 Ho-oh are in the Interval n element [860:980] so even if I catch 1000 Ho-oh’s chances are that I only get like 130 different ones. I expected a kind of Gaussian distribution and well that fits quite nicely if you look at the plot
Here we have the number of Ho-ohs I caught with that n. As you can see the amount of clones I got is really big. The blue line is gaussian fit. The error margins are quite big, but that’s probably because 70 is not enough (but there is no way I’d want to repeat this even more often.
Practical implications
The obvious one would be when reseting legendarys before you run into them take your time. That way n will evolve a little further giving you a bigger interval. And change times. Otherwise you will end up with the same iv distribution very often and thus wasting even more time. In RSFL walk around a little and save like once every 20 attempts so you get a different seed. Only the new games don’t have this problem at all.