I might as well go ahead and follow up on my post from
13 years ago. (Unfortunately the link to the Japanese site is broken now so my translation is the only thing remaining from back then.)
I figured out in depth how FRLG's RNG2 (second RNG address that determines when an encounter occurs, 0x3005000 in UE version, 0x3005040 in J version) works for encounters. I am quite sure that others already know all this, but I want to experience understanding it for myself so I can explain how it works in this topic.
Before I give the details, here are a couple files showing that it is possible to get to Pewter City with 0 encounters (as mkdasher alluded to before) but with way too much walking. It is also possible to get to Pewter City with 1 encounter and a better path than the currently published any% run:
*
https://tasvideos.org/UserFiles/Info/639258969841731170 (0 encounters)
*
https://tasvideos.org/UserFiles/Info/639258972459778916 (1 encounter)
----
First, RNG2 uses a different formula from normal RNG:
val = val*0x41C64E6D + 0x3039
(the normal RNG has +0x6073 instead of +0x3039)
Second, RNG2 is only called when getting a number to determine whether a random encounter occurs. If the number mod 1600 is less than a certain value (dependent on area and an "accumulation" value), a random encounter is triggered. I will call this value N.
The value N is calculated from area encounter rate and the "accumulation" (0x3005006 in UE, 0x3005046 in J) as follows:
N = round_down(Rate*16*modifier) + round_down(Accumulation*16/200)
where modifier is 1 if not biking and 0.8 if biking (there are other modifiers in the translation post I linked, which I did not test).
The accumulation generally increases as you take steps without encounter (provided repel is not in effect), and works as follows:
* When switching areas, or after any battle, or after a reset, accumulation resets to 0.
* Any time RNG2 is rolled and no encounter occurs, add to the accumulation value the encounter rate of the tile (same number as "Rate" in the formula above), except when repel is in effect; in that case, accumulation resets to 0.
For example, in grass with a rate of 21 and repel is not in effect, add to the normal 336 the number 21*X*16*/200 (rounded down), where X is the number of steps where RNG2 was rolled without encounter. The "accumulation" explains why, in grass with a rate of 21, values slightly above 336 sometimes triggered encounters and sometimes not.
One other thing to note is that not all instances of walking in encounterable tiles will call RNG2:
1) When entering a new area (or after any battle or after a reset), you get a number of "free" steps where RNG2 is unlikely to be called (although it is possible for RNG2 to be called anyway randomly). The number of free steps already used up is stored in address 0x3005008 in UE version and 0x3005048 in J version. The number of free steps you are given depends on the Rate:
* If Rate is less than 10, you get 8 free steps.
* If Rate is between 10 and 19, you get 7 free steps.
* If Rate is between 20 and 29, you get 6 free steps, etc.
Note that it is still possible to call RNG2 during a free step with a low probability (depending on a called number from the normal RNG).
2) After using up all free steps, when entering an encounter area by walking from a non-encounter tile to an encounter tile (or between two encounter tiles of different types), there is a roughly 1/2 chance that RNG2
isn't called, giving you another free step. This does not apply when walking within an encounter area, so encounter steps are not avoidable except in a small number of cases.
The rates for each area that I found (possible that I missed some areas) are as follows:
* All grass except Viridian Forest and Route 21 grass (south of Pallet Town) and Three Isle Port grass (Dunsparce): Rate=21
* Viridian Forest and Route 21 grass: Rate=14
* Three Isle Port grass: Rate=1
* All caves except Diglett Cave: Rate=7
* Diglett Cave: Rate=5
* Pokemon Mansion (except basement) and Power Plant: Rate=7
* Pokemon Mansion's basement: Rate=5
* Pokemon Tower 3F: Rate=2
* Pokemon Tower 4F: Rate=4
* Pokemon Tower 5F: Rate=6
* Pokemon Tower 6F: Rate=8
* Pokemon Tower 7F: Rate=10
* All water except within cities/towns, and all water in Four Island regardless: Rate=2
* Water within cities/towns: Rate=1