Jump to content

RNG correlation (Generation I): Difference between revisions

m
→‎Mechanics: Undid a superfluous change when doing text replacement ("~" for approximation should not be changed).
>Bbbbbbbbba
(A lot of analysis that may not be easy to understand...)
 
m (→‎Mechanics: Undid a superfluous change when doing text replacement ("~" for approximation should not be changed).)
 
(3 intermediate revisions by 2 users not shown)
Line 20:
* For each value of the low byte, there are two ranges of the high byte.
* For each value of the high byte, there are three ranges of the low byte.
For grass with encounter rate 25, when the low byte is 0, the two ranges of the high byte are 13 ~ 26 and 141 ~ 154.<ref>[https://pastebin.com/szC2vDDk Nidoran DV formula]</ref> Since the Attack DV and the Speed DV are the high nybbles of their respective bytes, they are more obviously correlated than the other two DVs. A complete list of possible DVs can be found [https://pastebin.com/iBT64Pkq here].
 
Note that, in unusual cases, an extra lag frame may happen between encounter check and DV generation. This may allow some "impossible" DVs to be generated.
 
==Effect on the catch rate==
In Generation I, whether a thrown Poké Ball successfully catches a wild Pokémon is determined by two random bytes, the first of them drawn by rejection sampling if the ball is better than a regular one: A Great Ball guarantees it to be in the range 0 ~ 200 (inclusive), and an Ultra Ball or a Safari Ball guarantees 0 ~ 150 (inclusive). Under normal circumstances, the Pokémon is caught if the first is less than or equal to the base catch rate of its species, and the second is less than or equal to an "HP factor" that is approximately inversely proportional to the percentage of remaining HP, and boosted specifically by Great Balls (but not Ultra Balls or Safari Balls). (Status effects affect the procedure in a complicated way.)<ref>[https://www.dragonflycave.com/mechanics/gen-i-capturing Gen I Capture Mechanics], The Cave of Dragonflies</ref>
 
Ostensibly, this means that the catch rate is min((C + 1) / B, 1) * min((F + 1) / 256, 1), where C is the base catch rate, F is the HP factor, and B is 256 for regular Poké Balls, 201 for Great Balls, and 151 for Ultra Balls and Safari Balls. However, when B is not 256, the rejection sampling would create an RNG correlation that may significantly affect the catch rate.
Line 31:
For example, consider Tauros in the Safari Zone. Without throwing bait or rock, C is 45, and a typical value of F is 87 (it can vary a little depending on the max HP of Tauros). Therefore the success rate of each Safari Ball should be (46 / 151) * (88 / 256) ≈ '''10.472%'''. However, simulation shows that, due to RNG correlation, the actual catch rate is only about '''6.633%'''.
 
In fact, this is close to the most devastating effect RNG correlation can have on the catch rate. When the first RNG value tried in the rejection sampling is between 0 and 150, the probability 10.472% should be accurate. Meanwhile, when the first RNG value tried is not between 0 and 150, the probability of success drops to about 1.113%. In general, the catch rate with RNG correlation is at least 151/225256 ≈ 59% of the "ideal" catch rate.
 
Some concrete analysis will illustrate why the effect is so large in this case. Experiment shows that each iteration of the rejection sampling takes 516 cycles (2.015625 rDIV periods), and there are 23960 cycles (93.59375 rDIV periods) between the last RNG call in the rejection sampling and the RNG call for the second random byte.<ref>Thanks entrpntr for those numbers.</ref> Assuming that the rejection sampling did not get 0 ~ 150 on the first try, we can consider the last three RNG calls:
# The second-to-last iteration of the rejection sampling, which must be in the range 151 ~ 255 for the rejection sampling to continue.
# The last iteration of the rejection sampling, which must be in the range 0 ~ 45 to have a chance to catch the Tauros.
# The second random byte, which must be in the range 0 ~ 87 to actually catch the Tauros.
Denoting those values as r<sub>1</sub>, r<sub>2</sub>, and r<sub>3</sub>, we have (r<sub>3</sub> - r<sub>2</sub>) - (r<sub>2</sub> - r<sub>1</sub>) = 93 or 94 (depending on the "sub-rDIV" value). However, those ranges are very "misaligned", andas the only way for all three values to bevisualized in their respective rangethe isgraph that:below.
 
* r<sub>1</sub> must be in the range 151 ~ 184,
[[File:Tauros RNG correlation.png|center]]
* r<sub>2</sub> must be in the range (r<sub>1</sub> - 94) / 2 ~ 45.
 
** This range shrinks as r<sub>1</sub> increases: It is 29 ~ 45 for r<sub>1</sub> = 151, and only 45 for r<sub>1</sub> = 184.
From the graph, it can be seen that the only way for all three values to be in their respective ranges is that:
* r<sub>1</sub> must be in the range 151 ~ 184,
* r<sub>2</sub> must be in the range (r<sub>1</sub> - 94) / 2 ~ 45.
** This range shrinks as r<sub>1</sub> increases: It is 29 ~ 45 for r<sub>1</sub> = 151, and only 45 for r<sub>1</sub> = 184.
Furthermore, there is no way to put another iteration of rejection sampling before this and still make a consistent RNG sequence. Therefore the second-to-last iteration is in fact the first iteration.
 
To put this in perspective, one can estimate the probability of success, given that the first RNG value is not between 0 and 150. Ideally, this probability should still be 10.472%, since the first value is rejected and should have no effect. In reality:
* To have a chance of success, this first value, i.e. r<sub>1</sub>, must be in the range 151 ~ 184, which happens with conditional probability 34/105.
* The next RNG value, i.e. r<sub>2</sub>, must hit a range with average length (1 + 17) / 2 = 9, which happens with probability 9/256.
Therefore, this conditional probability can be estimated as 34/105 * 9/256 ≈ 1.138%. (The actual probability is even lower, because the above analysis is optimistic about the "sub-rDIV" value.)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.