IV Distribution of Legendaries in Emerald: Edit

Status
Not open for further replies.

Blue Kirby

Never back down.
is a Top Tutor Alumnusis a Site Content Manager Alumnusis a Battle Simulator Admin Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnusis a Past SPL Championis a Three-Time Past WCoP Champion
Currently Working On:
- Initial cleanup


Here's the original article:

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=&quot]u32 randbuf=0;[/FONT]
[FONT=&quot]u16 pokerand() {[/FONT]
[FONT=&quot] randbuf = (randbuf*0x41C64E6D)+0x6073;[/FONT]
[FONT=&quot] return (randbuf >> 16);[/FONT]
[FONT=&quot]}[/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.
 

Blue Kirby

Never back down.
is a Top Tutor Alumnusis a Site Content Manager Alumnusis a Battle Simulator Admin Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnusis a Past SPL Championis a Three-Time Past WCoP Champion
What's been rewritten so far:

Many people have wondered why they've somehow managed to get an exact "clone" of a legendary Pokemon they've already caught. In some cases, people end up catching the same Pokemon on different cartridges! Why is this the case? The often overlooked underlying factor here is the method in which the game generates the captured Pokemon.

Theory
Pokemon games call upon a pseudo random number generator to determine the IVs of Pokemon upon capture. What does this mean to us? Although the IVs of a Pokemon you caught may appear to be random, they cannot truly be referred to as randomized due to the way in which they were arrived at.

Computer random number generators don't actually produce numbers randomly. They take what is known as a "seed" that determines the outcome. The seed itself is a number too, but it is generated as a result of a real-time event. The action that causes the seed to be selected is referred to as seeding. So, what does this have to do with the IVs of that Azelf you just caught? They were, in fact, sitting on a predetermined list of possible IV distributions for it. This list is present in each Pokemon game.

How Seeding Works

Pokemon Ruby, Sapphire, Fire Red and Leaf Green all seed when you begin a new game. Diamond and Pearl seed each and every time you load your game, in addition to the seed that takes place when you create a new one. Emerald, however, operates differently. Emerald never seeds except for when the player chooses their character's name.



<Going through theoretical content currently>



What does this all mean?
In practice, when resetting for legendary Pokemon in Emerald, take your time. That is, vary the amount of time between loading your game and initiating your encounter with the Pokemon. Otherwise, you'll end up receiving the same IV distribution a number of times, achieving nothing. For that little bit of time you spend making sure you're not getting the same IV spreads constantly, you'll save a lot of time when it comes to finally catching your dream Pokemon! Happy hunting!
 
Hmm, this is my situation:

On my emerald I've caught 3 shiny mews (using the rebattle code), and they have the exact same ivs and nature.

Is it possible for mew to get a shiny mew with different Ivs and/or nature?

You should add shiny information to that, if you have the support for it.
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
Many people have wondered why they've somehow managed to get an exact "clone" of a legendary Pokemon they've already caught. In some cases, people end up catching the same Pokemon on different cartridges! Why is this the case? The often overlooked underlying factor here is the method in which the game generates the captured Pokemon.
'here' not 'he'.

Computer random number generators don't actually produce numbers randomly. They take what is known as a "seed" that determines the outcome. The seed itself is a number too, but it is generated as a result of a real-time event. The action that causes the seed to be selected is referred to as seeding. So, what does this have to do with the IVs of that Azelf you just caught? They were, in fact, sitting on a predetermined list of possible IV distributions for it. This list is present in each Pokemon game.
I wouldn't say that the seed value determines the outcome. It just provides the starting number from which the RNG generates its pseudo-random list of numbers.

Imagine a huge roulette wheel containing each of the numbers 0 to n in a predetermined place (not in order). The seed is basically the starting position of the roulette wheel. Whenever the random number generator is called, the roulette wheel is made to point to the next number and that number is returned. That's how RS, FRLG and DP work, differing only in the way that the seed (i.e. the starting position) is decided at the start of the game, as you say afterwards.

In Emerald, however, the starting position of the roulette wheel is always the same at the start of the game, but the roulette wheel is constantly spinning, at the rate of about 60 numbers per second. Whenever the random number generator is called, the roulette wheel is made to point to the next number, that number is returned and the wheel continues to spin.

That's how I'd explain the process.

In practice, when resetting for legendary Pokemon in Emerald, take your time. That is, vary the amount of time between loading your game and initiating your encounter with the Pokemon. Otherwise, you'll end up receiving the same IV distribution a number of times, achieving nothing. For that little bit of time you spend making sure you're not getting the same IV spreads constantly, you'll save a lot of time when it comes to finally catching your dream Pokemon! Happy hunting!
I'd expand on this paragraph, since you can actually use Emerald's feature to your advantage. For example, if you find a wild shiny Pokemon a few moments after you soft-reset, then you will find the exact same shiny Pokemon every time you soft-reset in Emerald if you time it perfectly, because "shininess" is also determined from the PID of the Pokemon, just as its IVs, nature and gender are. You could also do the same for a Pokemon you find that has excellent IVs. If, after around 5 seconds of soft-resetting, you encounter a Modest 23/28/23/30/29/25 IV Kyogre, you'll encounter it again if you soft-reset again for it and wait 5 seconds.
 

Blue Kirby

Never back down.
is a Top Tutor Alumnusis a Site Content Manager Alumnusis a Battle Simulator Admin Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnusis a Past SPL Championis a Three-Time Past WCoP Champion
I wouldn't say that the seed value determines the outcome. It just provides the starting number from which the RNG then generator its pseudo-random list of number.
I didn't intend to just leave the description at what was currently posted; it's just what I've finished so far. That was just supposed to provide a transition between the introduction and the specifics of the theory under "How Seeding Works". However, I'll reword that to be more clear; I'll change it to point out that it aids in determining the outcome.

Imagine a huge roulette wheel containing each of the numbers 0 to n in a predetermined place (not in order). The seed is basically the starting position of the roulette wheel. Whenever the random number generator is called, the roulette wheel is made to point to the next number and that number is returned. That's how RS, FRLG and DP work, differing only in the way that the seed (i.e. the starting position) is decided at the start of the game, as you say afterwards.

In Emerald, however, the starting position of the roulette wheel is always the same at the start of the game, but the roulette wheel is constantly spinning, at the rate of about 60 numbers per second. Whenever the random number generator is called, the roulette wheel is made to point to the next number, that number is returned and the wheel continues to spin.
That's a really good analogy, actually. I'll probably use something along those lines rather than what I was currently working on. The way that you've put it gets the point across much more clearly.

I'd expand on this paragraph, since you can actually use Emerald's feature to your advantage.
Will do.
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
Hmm, this is my situation:

On my emerald I've caught 3 shiny mews (using the rebattle code), and they have the exact same ivs and nature.

Is it possible for mew to get a shiny mew with different Ivs and/or nature?

You should add shiny information to that, if you have the support for it.
A Pokemon being shiny depends on the PID of that Pokemon and your Trainer ID that you get when you start the game. That means that it is extremely unlikely that you'll ever get a different shiny Mew from your Emerald.
 
A Pokemon being shiny depends on the PID of that Pokemon and your Trainer ID that you get when you start the game. That means that it is extremely unlikely that you'll ever get a different shiny Mew from your Emerald.
...And it would also mean that it is extremely likely that when I soft-reset for other legendaries, and get the timing right, I would catch a shiny *Insert Pokemon's name Here* with the nature and Ivs same as my shiny Mew, correct?

In the past, I've caught a shiny Rayquaza on this game. I know it has the same nature as my shiny mew, but I have no clue what the Ivs are on the Shiny Rayquaza as I no longer have it.
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
...And it would also mean that it is extremely likely that when I soft-reset for other legendaries, and get the timing right, I would catch a shiny *Insert Pokemon's name Here* with the nature and Ivs same as my shiny Mew, correct?

In the past, I've caught a shiny Rayquaza on this game. I know it has the same nature as my shiny mew, but I have no clue what the Ivs are on the Shiny Rayquaza as I no longer have it.
Yes, exactly. If you're lucky enough that your Trainer ID is such that you encounter a shiny Pokemon after 10 seconds of resetting, say, you can try getting the timing right and soft-reset for a shiny Rayquaza, a shiny Kyogre, a shiny Groudon, etc. All of them, however, with have exactly the same IVs and nature (and PID). That means that the shiny Rayquaza you had before had almost certainly the same IVs as your shiny Mew.
 
Yes, exactly. If you're lucky enough that your Trainer ID is such that you encounter a shiny Pokemon after 10 seconds of resetting, say, you can try getting the timing right and soft-reset for a shiny Rayquaza, a shiny Kyogre, a shiny Groudon, etc. All of them, however, with have exactly the same IVs and nature (and PID). That means that the shiny Rayquaza you had before had almost certainly the same IVs as your shiny Mew.
Then, all that I need to do is figure out the timing!

My Trainer ID has to be like that- since I got 3 Shiny Mews!

This should be mentioned in the guide.

**SHINY** Mew - #151 (Adamant)
HP: 24 - 26
Att: 10 - 13
Def: 31
SpA: 0 - 3
SpD: 24 - 26
Speed: 7 - 9

That's my Mew....Maybe a half decent Regirock?
 

chaos

is a Site Content Manageris a Battle Simulator Administratoris a Programmeris a Smogon Discord Contributoris a Contributor to Smogonis an Administratoris a Tournament Director Alumnusis a Researcher Alumnus
Owner
I wouldn't say that the seed value determines the outcome. It just provides the starting number from which the RNG generates its pseudo-random list of numbers.

Imagine a huge roulette wheel containing each of the numbers 0 to n in a predetermined place (not in order). The seed is basically the starting position of the roulette wheel. Whenever the random number generator is called, the roulette wheel is made to point to the next number and that number is returned. That's how RS, FRLG and DP work, differing only in the way that the seed (i.e. the starting position) is decided at the start of the game, as you say afterwards.
But that isn't true. The seed value _does_ determine the outcome. The roulette wheel analogy does not work because it depends on how hard you spin the wheel (and various other environmental variables) in addition to the initial starting position. A pseudo-RNG will always return the same set of values given the same seed.
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
But that isn't true. The seed value _does_ determine the outcome. The roulette wheel analogy does not work because it depends on how hard you spin the wheel (and various other environmental variables) in addition to the initial starting position. A pseudo-RNG will always return the same set of values given the same seed.
What do you mean by 'how hard you spin the wheel'? The wheel moves one position whenever the RNG is invoked. That's "how hard the wheel is spinning". It happens that, in Emerald, the RNG is also called needlessly (probably via an interrupt) about once every 1/60 of a second, so that makes the wheel spin continuously. And yeah, given the same seed the RNG will always return the same set of values. Isn't that the same thing as saying "the roulette wheel will always produce the same numbers given that you start it from the same place"?
 

chaos

is a Site Content Manageris a Battle Simulator Administratoris a Programmeris a Smogon Discord Contributoris a Contributor to Smogonis an Administratoris a Tournament Director Alumnusis a Researcher Alumnus
Owner
I skipped over the part of it just moving one place. A "roulette wheel" conjures specific images... using it in such a weird way is likely to confuse people (or have people ignore the non-standard usage, like I just did)
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
Well, actually that IS the way I view good linear congruental RNGs, of which the Pokemon RNG is one.
 
That's how RS, FRLG and DP work, differing only in the way that the seed (i.e. the starting position) is decided at the start of the game, as you say afterwards.

In Emerald, however, the starting position of the roulette wheel is always the same at the start of the game, but the roulette wheel is constantly spinning, at the rate of about 60 numbers per second. Whenever the random number generator is called, the roulette wheel is made to point to the next number, that number is returned and the wheel continues to spin.
Just to clarify things a bit, when you say "start of the game", you mean when the gamesave is loaded, right? Not when the gamesave was originally created via "New Game"?

EDIT: And I know this thread is primarily for the RNG of the handheld games but it might be a good idea for somebody knowledgeable to research the GCN games to see how those games are seeded. Also would be interesting to know if the Jirachi bonus disk uses the RNG of the GBA game or has one itself. I know people who SR for Jirachi (*coughcoughDavycough*) try to rush through the GBA part of the SR as quickly as possible. Wonder how much that plays into IV distribution.
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
Yes, the "start of the game" here means when the game is loaded. Although the same thing holds when you start a new game too.

At the start of a NEW game, the Trainer ID is chosen, by the way. This, incidentally, means that, in Emerald, the Trainer ID should be one out of maybe 2000 or 3000, even though it's a number between 0 and 65535 (and so should be one out of more than 65000). This is because most people roughly take the same amount of time to read the instructions before typing in their name when starting a new game, and the Trainer ID is determined at that point in time. I don't think anyone checked this before, but it would be interesting to confirm.
 
Hmm, but how does it work with the Collosseum Bonus disk (when you get Jirachi)?

Also, say I Soft-reset in emerald and I get a Groundon with 31/31/20/15/25/31 BUT it's quirky nature. Would it be possible to get it (with the same ivs) in a different nature? It depends on what the Ivs are (meaning it varies with Ivs), right?
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
Hmm, but how does it work with the Collosseum Bonus disk (when you get Jirachi)?
I don't know anything about how that works.

Also, say I Soft-reset in emerald and I get a Groundon with 31/31/20/15/25/31 BUT it's quirky nature. Would it be possible to get it (with the same ivs) in a different nature? It depends on what the Ivs are (meaning it varies with Ivs), right?
A 31/31/20/15/25/31 Pokemon only exists in at most 6 natures and at least 2, and this is true for every IV list. There might be exceptions if you catch this in Emerald though (because the RNG is called very often, and hence it might happen that it's called uselessly in between the calls to the RNG to generate the Pokemon!). However, this would add between 4 and 10 other natures, and hence there might still be natures that don't exist for your particular IV list. Also this happens very rarely (but it can happen)
 
I don't know anything about how that works.


A 31/31/20/15/25/31 Pokemon only exists in at most 6 natures and at least 2, and this is true for every IV list. There might be exceptions if you catch this in Emerald though (because the RNG is called very often, and hence it might happen that it's called uselessly in between the calls to the RNG to generate the Pokemon!). However, this would add between 4 and 10 other natures, and hence there might still be natures that don't exist for your particular IV list. Also this happens very rarely (but it can happen)
If I wanted to get that 31/31/20/15/25/31 Pokemon in a different nature, would it need the same and/or different timing for the one I "caught" before?
 

X-Act

np: Biffy Clyro - Shock Shock
is a Site Content Manager Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Researcher Alumnusis a Top CAP Contributor Alumnusis a Top Tiering Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnus
If I wanted to get that 31/31/20/15/25/31 Pokemon in a different nature, would it need the same and/or different timing for the one I "caught" before?
If you're doing it in Emerald, it MUST have different timing. On anything else, timing is not important as the RNG's seed varies whenever you reload the game.
 
Due to the nature of how Emerald seeds on timing, wouldn't mass hatch be much more favorable to soft-reset breeding in that game? Unless you happen to know the exact timing (and able to pull it off!) needed to make certain IVs pass, that is.
 
this is all very interesting (including a damn rebattle code in emerald wtf is that about davy!?!? lol).

i've been breeding in emerald with moderate success. i managed a rhyhorn with 27 / 31 / 31 / x / 31 / 31 but it had lightningrod so i just use it as breeding fodder.

i got a 29 / 31 / 31 / x / 29 / 31 cubone
a 29 / 31 / 31 / x / 31 / 31 teddiursa
a 29 / 31 / 31 / x / 22 / 31 growlithe
and a 31 / 31 / 28 / x / 30 / 28 marill

all were bred relatively quickly using the SR method.

now granted i used the same male parent to spawn most of these, i know that i encountered the same IVs while SRing more than once. this is particularly true on the poliwag i'm working on right now, which i've gotten what appears to be a great poliwag at first glance (20/12/10/0/10/15 at level 5 means every IV is 20-31) but really the best is an "Outstanding" special defense IV according to the Battle Tower guy three times in maybe three hours.

would i be better off maybe running around a bit before taking eggs again? or will my IVs eventually fall into place, and the timing right now isn't quite on?
 
dear sir, if you had bothered to go through the article, you would have known that breeding achievements are not what this thread even remotely seeks to address. the thread is solely for the purpose of explaining the way the pseudorandom number generator in emerald functions, and how that could be exploited to catch legendaries with higher IVs.

oh, and a rebattle code is something that allows you to battle a legendary again, since legendaries usually tend to 'vanish' from the place where you fought them after a battle with them.

anyway, the primary reason why i posted this was to inquire on the status of this article :toast:
 

Blue Kirby

Never back down.
is a Top Tutor Alumnusis a Site Content Manager Alumnusis a Battle Simulator Admin Alumnusis a Programmer Alumnusis a Smogon Discord Contributor Alumnusis a Top Contributor Alumnusis a Smogon Media Contributor Alumnusis an Administrator Alumnusis a Past SPL Championis a Three-Time Past WCoP Champion
I'm yet to decide on how specific I should be when explaining the process - some are opposed to the idea of releasing "too much" information, while others believe it should be available for all.

Basically I'm going for a "happy medium", at least to begin with.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top