# Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

## Pokémon Discussion

### Does anyone know the probability of this? - Page 1

Previous Page

- 1

Next Page

#### Does anyone know the probability of this?

Posted by: Nostalgia
Date: 2018-09-15 12:04:04
I just got a trainer ID of 22222. I'm trying to work out the probability of this occurring because it seems it's not as simple as the probability of the same five digits occurring - because the highest trainer ID you can get is 65535. So you can't get for example a trainer ID number starting in 9.
Also this in a third gen game and I know Pokemon games starting from Generation VII have six digit trainer ID's now.
I was just wondering if anyone might know the answer. :)

#### Re: Does anyone know the probability of this?

Posted by: IceFlame
Date: 2018-09-15 12:16:08
If it goes from 0 to 65535, and you're looking for 00000,11111..55555, that would be 6/65536 or just under 1 in 10000.

#### Re: Does anyone know the probability of this?

Posted by: Torchickens
Date: 2018-09-15 12:23:15

> If it goes from 0 to 65535, and you're looking for 00000,11111..55555, that would be 6/65536 or just under 1 in 10000.

This.
At a first look it might be simply be (theoretical odds) 1/65536 for any combination (the same chance as any ID such as say 12345 or 49120), and like IceFlame said if you want 5 of the same digits it would be 5/65536 (note IceFlame you forgot you can't get 66666 in Generation III) but with any pseudo-random number generator the 'experimental odds' might be a little different (not sure to what extent), especially Emerald with its broken RNG.

#### Re: Does anyone know the probability of this?

Posted by: IceFlame
Date: 2018-09-15 12:35:44
I wasn't counting 66666, but I counted 00000 - is that one possible?

#### Re: Does anyone know the probability of this?

Posted by: Sherkel
Date: 2018-09-15 13:22:21
Yep, I've gotten 00000 before, so it's 6/65536. This is especially lucky in FireRed, LeafGreen, or Emerald, as you can't manipulate your ID in those (unless you run a script to keep loading a state before you confirm your name).

#### Re: Does anyone know the probability of this?

Posted by: Torchickens
Date: 2018-09-15 14:19:13

> I wasn't counting 66666, but I counted 00000 - is that one possible?

Oops, my mistake. :( Yeah, I forgot about the 00000 one. Sorry for my carelessness.

> This is especially lucky in FireRed, LeafGreen, or Emerald, as you can't manipulate your ID in those (unless you run a script to keep loading a state before you confirm your name).

Ah OK. Interesting!

#### Re: Does anyone know the probability of this?

Posted by: Nostalgia
Date: 2018-09-15 15:02:24

> If it goes from 0 to 65535, and you're looking for 00000,11111..55555, that would be 6/65536 or just under 1 in 10000.

Less chance than encountering a shiny Pokemon. Nice. Though 55555 would have been better. ;D

> Yep, I've gotten 00000 before, so it's 6/65536. This is especially lucky in FireRed, LeafGreen, or Emerald, as you can't manipulate your ID in those (unless you run a script to keep loading a state before you confirm your name).

Yes it's FireRed. I've always like cool trainer ID's so I reset for them. I know some shiny hunters do it as well because they seem to think having a patterned trainer ID makes them more lucky lol. I just like them because they look neat and the ID stays with you for the rest of the game and it's attached to every Pokemon to catch or breed so having something unique looks better than something really generic like 01493. I wasn't sure whether to keep this one though because I usually only like ones that start with 5 or 6, but given how lucky this is I'll keep it.

#### Re: Does anyone know the probability of this?

Posted by: ISSOtm
Date: 2018-09-15 21:17:02
I've had to manipulate my TID in Red to test SGB boot ROM durations (the boot ROM forwards the whole ROM header to the SNES, which may or may not stop clocking the CPU; however, the code paths between sending a 1 bit and a 0 bit differ by 1 M-cycle, which further bleeds into a LY waitloop… It's a mess to emulate accurately :')
Procedure:
1. Let intro play out
2. While game title is sliding in, hold START
3. During blank screen, release START and hold A
4. There you go, TID 0880something, 100% consistent :) (Only tested on a French version. Would differ with other ROMs, since they have a different header – any alteration to the ROM alters the global checksum as well, which alters the SGB boot timing..!)

#### Re: Does anyone know the probability of this?

Posted by: Sherkel
Date: 2018-09-15 21:56:19
I guess it's my turn for a "Chickasaurus moment" because I want to hammer down how lucky this is and need to calm down anyway.
The GBA has an internal timer that increments by 1 every CPU cycle, which is about 59.59 nanoseconds or 16.8 million (2^24) increments per second. Most games don't bother to use this, and instead opt to time things by incrementing by 1 every time the screen is refreshed (VBlank), which is about 60 times per second or one frame. In Gen III, these frames are the exact same "frames" used in players' RNG calculations. This is because nearly every RNG operation done by the game is done using the current value in memory that changes every frame through a linear congruential algorithm (multiply by some set number then add some set number,) a very primitive way of creating "random" numbers (not that they ever expected anyone to bother to figure it out). This value (the seed) starts at 0 in Emerald, and 5A0 in Ruby or Sapphire with a dead battery. In FireRed, LeafGreen, and live battery Ruby and Sapphire, there's an unpredictable algorithm run on startup that determines the starting value, which means you're screwed for RNGing on a physical copy of those. The LCG is arguably less "primitive" in that it ends up allowing every possible 32-bit value to occupy that memory location, still less than the amount of possible IV/nature combinations, but enough that most wouldn't care. 524288 of these values (2^32 / 8192) result in shiny Pokémon, as that many return "true" when put through an algorithm using both your ID and secret ID as variables (simplifying a lot here, but it's not the main focus anyway.)
So we have frames, and we have the GBA's internal timer. The 60 Hz timer for RNG was mostly retired in Gen IV (initial seed generation aside), was completely nonexistent in Gen V unless you were in the Entralink, has an unknown function in Gen VI, and finally returned in Gen VII. In Gen III, it still determined everything, except for one thing…IDs in FireRed, LeafGreen, and Emerald. These used the 16.8 MHz timer, which I'm guessing VBA stumbles with now and then, making these nice save files technically legal hacks:
[img]https://i.imgur.com/GYI3lDk.png[/img]
[img]https://i.imgur.com/jqZ4LjY.png[/img]
(had to bite the bullet with VBA in order to run the script I mentioned a few posts above)
Odder yet, the secret ID is generated by using the value that changes with every increment on the 60 Hz timer! Odder again, the value in question is rewritten when the normal ID is generated, making these also impossible to manipulate without an emulator! I can't come up with any explanation for this other than:
[img]https://i.imgur.com/Im4xlB7.png[/img]
So yeah, a vanity ID on a physical copy of one of these games…kind of a big deal. ;D
[size=8pt](In Ruby and Sapphire, the ID is determined from the upper 16 bits of the seed at the end of the Birch intro, and then the LCG is incremented by 2 and the upper 16 bits of that are used to determine the secret ID. So in those, you can't get the shiny IVs you want with just any visible ID, because it's tied directly to the secret one.)[/size]
And yeah, Gen I ID abuse is fairly easy but also very limited with how much you can reliably get. It's a must for any sort of glitched run, though, because that value factors into ACE. It's the reason the rules have become so much more strict ever since those games' RNG was cracked; prior to its discovery, nothing emulated it properly, and now there's just one emulator that does, plus all the values Isso mentioned that one has to take into account.

#### Re: Does anyone know the probability of this?

Posted by: Nostalgia
Date: 2018-09-16 06:39:50

> In FireRed, LeafGreen, and live battery Ruby and Sapphire, there's an unpredictable algorithm run on startup that determines the starting value, which means you're screwed for RNGing on a physical copy of those.

I've never tried RNGing anyway and I don't completely understand how to do it and I assume it's harder to do on a real copy compared to a ROM. I've read it's supposedly very effective to do in Emerald, but its not hard to breed Pokemon with good IV's. RNGing for a perfect Pokemon doesn't seem fun anyway. I do however like soft resetting for good natures/IV's.
Thanks for all the info though. That's exactly why I asked this question because I know there are much more knowledgeable members on this forum than me when it comes to the inner workings of the games.

> So yeah, a vanity ID on a physical copy of one of these games…kind of a big deal. ;D

I only play on physical copies, never ROM's, so this is good to hear. :D

> And yeah, Gen I ID abuse is fairly easy but also very limited with how much you can reliably get. It's a must for any sort of glitched run, though, because that value factors into ACE. It's the reason the rules have become so much more strict ever since those games' RNG was cracked; prior to its discovery, nothing emulated it properly, and now there's just one emulator that does, plus all the values Isso mentioned that one has to take into account.

I just used ws m in Yellow and coin case/bad clone ACE in Gold/Crystal to change my ID easily. I remember Torchickens had to help me with Yellow. 8)

#### Re: Does anyone know the probability of this?

Posted by: Sherkel
Date: 2018-09-16 08:50:31
The main point is that an ID in FireRed is determined by timing of one 16 millionth of a second as opposed to one 60th of a second in games like Ruby or one 30th in ones like Diamond and HeartGold. Hitting A in a 59 nanosecond interval is humanly impossible.
ACE is the surefire way to a specific ID in Gens I/II, no doubt. I was just referring to their initial generation after hitting "New Game".
Looking it back over now, I left out a lot, and also included a lot of unnecessary info, but oh well, it seems like I answered whatever questions you may have had. :) Glad to help.

#### Re: Does anyone know the probability of this?

Posted by: Torchickens
Date: 2018-09-17 09:44:22

> I guess it's my turn for a "Chickasaurus moment" because I want to hammer down how lucky this is and need to calm down anyway.
> The GBA has an internal timer that increments by 1 every CPU cycle, which is about 59.59 nanoseconds or 16.8 million (2^24) increments per second. Most games don't bother to use this, and instead opt to time things by incrementing by 1 every time the screen is refreshed (VBlank), which is about 60 times per second or one frame. In Gen III, these frames are the exact same "frames" used in players' RNG calculations. This is because nearly every RNG operation done by the game is done using the current value in memory that changes every frame through a linear congruential algorithm (multiply by some set number then add some set number,) a very primitive way of creating "random" numbers (not that they ever expected anyone to bother to figure it out). This value (the seed) starts at 0 in Emerald, and 5A0 in Ruby or Sapphire with a dead battery. In FireRed, LeafGreen, and live battery Ruby and Sapphire, there's an unpredictable algorithm run on startup that determines the starting value, which means you're screwed for RNGing on a physical copy of those. The LCG is arguably less "primitive" in that it ends up allowing every possible 32-bit value to occupy that memory location, still less than the amount of possible IV/nature combinations, but enough that most wouldn't care. 524288 of these values (2^32 / 8192) result in shiny Pokémon, as that many return "true" when put through an algorithm using both your ID and secret ID as variables (simplifying a lot here, but it's not the main focus anyway.)
> So we have frames, and we have the GBA's internal timer. The 60 Hz timer for RNG was mostly retired in Gen IV (initial seed generation aside), was completely nonexistent in Gen V unless you were in the Entralink, has an unknown function in Gen VI, and finally returned in Gen VII. In Gen III, it still determined everything, except for one thing…IDs in FireRed, LeafGreen, and Emerald. These used the 16.8 MHz timer, which I'm guessing VBA stumbles with now and then, making these nice save files technically legal hacks:
> [img]https://i.imgur.com/GYI3lDk.png[/img]
> [img]https://i.imgur.com/jqZ4LjY.png[/img]
> (had to bite the bullet with VBA in order to run the script I mentioned a few posts above)
> Odder yet, the secret ID is generated by using the value that changes with every increment on the 60 Hz timer! Odder again, the value in question is rewritten when the normal ID is generated, making these also impossible to manipulate without an emulator! I can't come up with any explanation for this other than:
> [img]https://i.imgur.com/Im4xlB7.png[/img]
> So yeah, a vanity ID on a physical copy of one of these games…kind of a big deal. ;D
> [size=8pt](In Ruby and Sapphire, the ID is determined from the upper 16 bits of the seed at the end of the Birch intro, and then the LCG is incremented by 2 and the upper 16 bits of that are used to determine the secret ID. So in those, you can't get the shiny IVs you want with just any visible ID, because it's tied directly to the secret one.)[/size]
> And yeah, Gen I ID abuse is fairly easy but also very limited with how much you can reliably get. It's a must for any sort of glitched run, though, because that value factors into ACE. It's the reason the rules have become so much more strict ever since those games' RNG was cracked; prior to its discovery, nothing emulated it properly, and now there's just one emulator that does, plus all the values Isso mentioned that one has to take into account.

Really interesting!
Also thanks, you flatter me.
I remember reading that luck on certain Game Boy (DMG/GBC) emulators isn't too accurate either, which is why many speedrunners only accept real hardware or more accurate ones for RNG abuse. Additionally is it true VisualBoyAdvance may have less frames per second than real hardware? I think this was mentioned on TASVideos Forums regarding the bad clone glitch somewhere.

#### Re: Does anyone know the probability of this?

Posted by: Sherkel
Date: 2018-09-17 12:00:55
Gambatte-Speedrun was a fork specifically created to emulate RBY's RNG correctly, and I think BGB got an update soon afterward to do the same. The reason it may have taken so long to get around to emulating correctly is that it has to do with instructions passed from the GBC's BIOS to the ROM, not just instructions in the ROM itself. I wouldn't be surprised if everything besides the initial seeding process worked correctly in versions before the update.
As for VBA, I don't know exactly, but I'm pretty sure if you left it open with a timer at the same time as a physical GBA, it would at least be off by more than one 16 millionth of a second.
Buuuut I don't care. :P I still moved one of those saves to a real Emerald cartridge and have shinies from it on my physical copy of Ultra Moon.

#### Re: Does anyone know the probability of this?

Posted by: ISSOtm
Date: 2018-09-17 14:36:59
Yeah, RBY's RNG runs off of DIV, which counts starting from the boot ROM.
Previous Page

- 1

Next Page