Personality value: Difference between revisions

→‎Gender: see my talk page
(Undo revision 2653306 by SnorlaxMonster – unless it changed GenIV/V, our prose and the actual algorithm should be equivalent, and these values correct https://github.com/pret/pokeruby/blob/9640df02dd8651d5b05cf3767f6c7e16a697db3b/src/pokemon_2.c#L209)
(→‎Gender: see my talk page)
Line 52: Line 52:
<code>00000000 00000000 00000000 <span style="background:#FF9999">00000000</span></code><br>
<code>00000000 00000000 00000000 <span style="background:#FF9999">00000000</span></code><br>


A Pokémon's [[gender]] is determined by the lowest eight digits (the lowest byte, highlighted in <span style="background:#FF9999">red</span> above) of ''p'' in binary form. Mathematically, this can be derived by calculating <code>''p'' [[wp:modulo operation|%]] 256</code>. Below, this value will be referred to as ''p<sub>gender</sub>''.
Prior to Generation VI, Pokémon's [[gender]] is determined by the lowest eight digits (the lowest byte, highlighted in <span style="background:#FF9999">red</span> above) of ''p'' in binary form. Mathematically, this can be derived by calculating <code>''p'' [[wp:modulo operation|%]] 256</code>. Below, this value will be referred to as ''p<sub>gender</sub>''.


In a Pokémon species' [[Pokémon base stats data structure in Generation III|base stat structure]], there is a value called the ''gender threshold'', a byte with a value ranging from 0 to 255. With the exception of a few special cases, ''p<sub>gender</sub>'' is compared to the gender threshold to determine if the Pokémon is male or female.
In a Pokémon species' [[Pokémon base stats data structure in Generation III|base stat structure]], there is a value called the ''gender threshold'', a byte with a value ranging from 0 to 255. With the exception of a few special cases, ''p<sub>gender</sub>'' is compared to the gender threshold to determine if the Pokémon is male or female.


If the gender threshold is not a special value (0, 254, or 255), ''p<sub>gender</sub>'' is compared to the gender threshold. If ''p<sub>gender</sub>'' is greater than or equal to the gender threshold, the Pokémon is male, otherwise it is female.
If the gender threshold is not a special value (0, 254, or 255), ''p<sub>gender</sub>'' is compared to the gender threshold. If ''p<sub>gender</sub>'' is greater than or equal to the gender threshold, the Pokémon is male, otherwise it is female. Because the comparison to determine gender is greater than or equal, Pokémon are not actually perfectly distributed between male and female according to the ideal ratios.


Because the comparison to determine gender is greater than or equal, Pokémon are not actually perfectly distributed between male and female according to the ideal ratios. Additionally, in Generation VI and VII, due to multiple bugs in the implementation of the gender generation algorithm, ''p<sub>gender</sub>'' can only be between 1 and 252 (inclusive), which skews Pokémon towards the more common gender and makes certain personality values impossible.
From Generation VI onward, the gender threshold is compared to a random number between 1 and 252 (inclusive) instead of ''p<sub>gender</sub>'' (which is between 1 and 255); this causes Pokémon with a "1:1" gender ratio to actually be distributed according to the ideal ratio.


If a species has a gender threshold of 255, it is genderless species (such as {{p|Magnemite}}), so is always genderless. If a species has a gender threshold of 254, it is a female-only species (such as {{p|Nidoran♀}}), so is always female. If a species has a gender threshold of 0, it is a male-only species (such as {{p|Nidoran♂}}), so is always male.
If a species has a gender threshold of 255, it is genderless species (such as {{p|Magnemite}}), so is always genderless. If a species has a gender threshold of 254, it is a female-only species (such as {{p|Nidoran♀}}), so is always female. If a species has a gender threshold of 0, it is a male-only species (such as {{p|Nidoran♂}}), so is always male.