Past Gen RNG Research

Kaphotics

Remodeling Kitchens
is a Top Researcher Alumnusis a Top Contributor Alumnus
Goldenrod Department Store RNG (HGSS)

Raffle
Code:
Rand % 100

0-3   (1st Prize)  4% for TMs
4-39  (2nd Prize) 36% for Balls
40-99 (3rd Prize) 60% for Berries (-> Rand%70 for 7 berries)
Code:
Message 0xb        ' All right. Please draw one!/r.../n.../r/0 '
017C 0x800c 0x64                     Rand%100
If 0x800c 0x28                       >= 40    (60%)
COMPARELASTRESULT 0x4 func_16        goto 3rd: Berry
If 0x800c 0x4                        >= 4    (36%)
COMPARELASTRESULT 0x4 func_17        goto 2nd: Ball
If 0x800c 0x0                        >= 0    (4%)
COMPARELASTRESULT 0x4 func_18        goto 1st: TM
End
Berry Branch:
Code:
Fanfare 0x913
SetvarNum 0x0 0x3    ' Wow!/nYou've got yourself the no. [VAR NUM: 2 .0 ] .0  prize!/rPlease take it./r/0 '
Message 0xc
017C 0x800c 0x46                     Rand%70
If 0x800c 0x3c                       >= 60
COMPARELASTRESULT 0x4 func_44        gives 0x009B = Oran
If 0x800c 0x32                       >= 50
COMPARELASTRESULT 0x4 func_45        gives 0x0096 = Chesto
If 0x800c 0x28                       >= 40
COMPARELASTRESULT 0x4 func_46        gives 0x0097 = Pecha
If 0x800c 0x1e                       >= 30
COMPARELASTRESULT 0x4 func_47        gives 0x0098 = Rawst
If 0x800c 0x14                       >= 20
COMPARELASTRESULT 0x4 func_48        gives 0x0099 = Aspear
If 0x800c 0xa                        >= 10
COMPARELASTRESULT 0x4 func_49        gives 0x009A = Leppa
If 0x800c 0x0                        >= 0
COMPARELASTRESULT 0x4 func_50        gives 0x0095 = Cheri
End
Vending Machine to verify blastoise_x
Code:
Rand % 64

0    - Give Extra Drink
1-63 - Don't Give Extra Drink
Code:
017C 0x800c 0x40                   varC rand%0x40
If 0x800c 0x0                      cmp(varC,0)
COMPARELASTRESULT 0x5 func_36      if != goto start
Fanfare 0x616                      play clang
SetvarItem 0x0 0x8001              textvar = itemname
Message 0x7                        "Clang!\rBonus! Another can of [item]\ndropped down.\r"
They gr/eq for their statements when checking high->low; in gen V they check low->high but with le/eq's. (script cmp values for reference)
 
Last edited:
  • Like
Reactions: Edu
Pokewalker information ( to be confirmed/disposed)

Apparently, sending a Pokemon back (returning home)
advances the IRNG by 40,
which results in a total animation of 232.

Which means, if you transfer two pokemon and have one returning home,
the first returning pokemon will have the nature of 233 and the second of 234.

Not clear:

Either sending a Pokemon in advances the IRNG by a total amount of 116 which results in total animation of 308
or sending a pokemon home which followed you.
To be exact it is not clear if a followed pokemon (not pokeradar) or sended in pokemon will advance the IRNG at all.

If anyone could confirm these points that would be nice
I know it’s been multiple years since this has been even mildly prominent, but I have confirmed this, and the Pokémon that follows you will add an additional IRNG frame. if you get a Pokémon to follow you, then catch 3 Pokémon, the followed Pokémon will have the nature of frame 233, and the caught Pokémon will have the natures of 234, 235, and 236 respectively.

Pokewalker PID Calculation:

Adapting Wichu's pseudocode to explain my findings:

Code:
rnd = CallIrng()
nature = rnd % 24 # There are actually 25 natures, so this prevents the Quirky nature being chosen, for some reason.
pid = (((trainerId ^ secretId) >> 8) ^ 0xFF) << 24 # the most significant byte of the PID is chosen so the Pokémon can never be shiny.
nature = nature - (pid % 25) # Adjusts the nature value so that when it is added to the PID, the resulting nature is the same as the original chosen nature. This can underflow to give a negative number.
pid = pid + nature # Creates the PID with the correct nature. If nature is negative, underflows to give a PID in the form 0xXXFFFFYY; otherwise, the PID is in the for 0xXX0000YY.
gr = GenderRate(species) # Gets the gender rate of the Pokémon (0-255; 0 is always male, 254 is always female, and 255 is genderless).
if (gender == male) #the gender forcing only seems to happen when necessary
pid = pid + ((((gr - (pid & 0xFF)) / 25) + 1) * 25) # Ensures gender is set to male without affecting nature.
if ((rnd & 1)  != (pid & 1)) # If ability does not match the chosen ability
pid = pid + 25 # Switches ability without affecting nature
end if
else if (gender == female)
pid = pid - (((((pid & 0xFF) - gr) / 25) + 1) * 25) # Ensures gender is set to female without affecting nature.
if ((rnd & 1)  != (pid & 1)) # If ability does not match the chosen ability
pid = pid - 25 # Switches ability without affecting nature
end if
end if
return pid
Key differences between Wichu's original posting and the above code:
Gender forcing algorithms only happen when the initial PID's gender does not match the forced gender. Single-gender and genderless Pokemon do not appear to have their PID adjusted by these steps.
The force female algorithm is pid - (), not pid + ()
The ability swap only happens when the gender is swapped.

Practical applications:
Gender rates:
31: Munchlax, Combee, Eevee, Torchic
63: Magby, Machop, Elekid, Abra
127: Everything with a 50/50 gender split
191: Azurill, Clefairy, Jigglypuff, Corsola, Cleffa, Igglybuff

Whenever the gender is forced, the natures with even numbers will be ability 0, and the natures with odd numbers will be ability 1. The only way to avoid this is to have an ID/SID combination that has the correct nature/ability combo and does not have a gender swap. As far as Munchlax is concerned, this makes Selfdestruct + Sassy + Thick Fat very difficult to get*, and Selfdestruct + Careful + Pickup impossible.

(EDIT: It might be worth noting that Hardy + Ability 1 is similarly unobtainable for Pokemon that are forced to be female.)

*Need [(((trainerId ^ secretId) >> 8) ^ 0xFF) << 24] mod 25 to be 23. Every other number either makes Sassy Munchlax go through the gender correction (and even nature -> Ability 0) or are innately even.
This pseudocode is close, but not quite right either, if I’m not mistaken. This is an adaptation of Wild Eep’s formula, tweaked to fit the results I’ve seen. A lot simpler in terms of gender swapping too.
Code:
pid0 = callIrng()  # Calls the IRNG value and advances the IRNG by 1. Despite being taken from gen 4 egg PIDs, this PID will be used as a loose guideline for the nonshiny PID to follow                                      
                                       
nature1 = pid0 % 24 # Determines the nature of the pokemon, cannot be quirky, probably by design. 24 (nature), 6 (characteristic priority), and 2 (ability) have a LCM of 24, rather than say 150, which I would assume is important for converting TID/SID to a PID in an efficient way.                                      

pid1 = (((TID ^ SID) >> 8) ^ 255) << 24) # Determines a non-shiny PID using TID and SID (If shiny pokemon WERE possible, it would be like the cute charm glitch but with more options)                                      
                                       
nature2 = nature1 - (pid1 % 25) # Finds a value that, when subtracted from pid1, will yield the same nature as pid. There's really not much interesting about this. It can be negative, and whether or not it is greater than 0 affects whether or not pid2 is the output.                                        
                                       
pid2 = pid1 - nature2  # pid2 will now have the same nature as pid0, despite actually being a variation of pid1. If it's in hexadecimal, you can tell at a glance which values are going to be affected by the nature change, as PID1 is always 0xXX000000                                      
                                       
if (0 < Gender Rate < 1) # Exclusively Male and exclusively female pokemon such as nidoran male and nidoran female are not affected by the gender swap, since they can have any PID while still retaining their gender                                      
                                       
if (Gender = Male, and nature 2 >= 0) # If nature 2 is 0 or greater, it is female by mod 256 and must be rerolled to male. If nature 2 is less than 0, it is male and may remain as is.                                      
                                       
gr ≈ (1-Gender Rate) * 300 # This will be used to advance the PID exactly enough to force a male gender. Has to be in increments of 50, or else it would affect the nature or ability. Should be 25% male = 200, 50% male = 150, 75% male = 100, 82.5% male = 50.                                      
                                       
pid3 = pid2 + gr # This will change the gender, without affecting ability or nature, 25 would change the ability, whereas 2 (if it were enough to shift gender alone) would change the nature.                                        
                                       
if (Gender = Female, and nature 2 < 0) # If nature 2 is 0 or greater, it is female by mod 256 and may remain so. If nature 2 is less than 0, it is male and must be rerolled to be female.                                        
                                       
gr ≈ (1-Gender Rate) * 300 # This will be used to advance the PID exactly enough to force a female gender. The values are the same as male, in increments of 50, or else it would affect the nature or ability. Should be 25% male = 200, 50% male = 150, 75% male = 100, 82.5% male = 50.                                      
                                       
pid3 = pid2 - gr # This will change the gender, without affecting ability or nature, 25 would change the ability, whereas 2 (if it were enough to shift gender alone) would change the nature. Additionally, since some of these values were subtracted from to reach their nature, they cannot be added to and are subtracted from again.                                        
                                       
return PID # Pokemon not affected by the process (such as genderless pokemon, pokemon with fixed genders, and pokemon who don't need a gender swap) will use pid2 as their final pid
Again, probably not something anyone’s really interested in at the moment, but I thought this might be a good place to document it
 
Last edited by a moderator:

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

Top