Pseudorandom number generation: Difference between revisions

m
Use multiplication sign
m (Text replacement - "{{ga|Pokémon Ranger}}" to "{{OBP|Pokémon Ranger|video game}}")
m (Use multiplication sign)
Line 13: Line 13:
Below, ''seed'' is a number between 0 and 0xFFFFFFFF. If the generator has been called previously, ''seed'' is the ''result'' value from the previous call to the generator.
Below, ''seed'' is a number between 0 and 0xFFFFFFFF. If the generator has been called previously, ''seed'' is the ''result'' value from the previous call to the generator.


*Pokémon Stadium: <code>''result'' = 0x41C64E6D * ''seed'' + 0x0000303B</code>
*Pokémon Stadium: <code>''result'' = 0x41C64E6D × ''seed'' + 0x0000303B</code>
** This equation is run several times depending on the N64's Count register, then {{wp|exclusive or|XOR}}'d with another pseudorandom value
** This equation is run several times depending on the N64's Count register, then {{wp|exclusive or|XOR}}'d with another pseudorandom value
*Pokémon Stadium 2<ref>[https://github.com/Lincoln-LM/stad2/blob/main/src/math.c stad2/src/math.c at main · Lincoln-LM/stad2]</ref>: <code>''result'' = 0x0019660D * ''seed'' + 0x3C6EF35F</code>
*Pokémon Stadium 2<ref>[https://github.com/Lincoln-LM/stad2/blob/main/src/math.c stad2/src/math.c at main · Lincoln-LM/stad2]</ref>: <code>''result'' = 0x0019660D × ''seed'' + 0x3C6EF35F</code>
*Pokémon Colosseum: <code>''result'' = 0x000343FD * ''seed'' + 0x00269EC3</code>
*Pokémon Colosseum: <code>''result'' = 0x000343FD × ''seed'' + 0x00269EC3</code>
*[[Game Boy Advance|GBA]] and [[Nintendo DS|DS]] games: <code>''result'' = 0x41C64E6D * ''seed'' + 0x00006073</code>
*[[Game Boy Advance|GBA]] and [[Nintendo DS|DS]] games: <code>''result'' = 0x41C64E6D × ''seed'' + 0x00006073</code>
*[[Distribution device|Pokémon Machine v2]] distributions: <code>''result'' = 0x41C64E6D * ''seed'' + 0x00003039</code>
*[[Distribution device|Pokémon Machine v2]] distributions: <code>''result'' = 0x41C64E6D × ''seed'' + 0x00003039</code>


In [[Generation III]] and [[Generation IV]], this algorithm is used for the following:
In [[Generation III]] and [[Generation IV]], this algorithm is used for the following:
Line 30: Line 30:
In [[Generation V]] and [[Generation VI]], the games instead use a 64-bit LCRNG as follows:
In [[Generation V]] and [[Generation VI]], the games instead use a 64-bit LCRNG as follows:


<code>''result'' = 0x5D588B656C078965 * ''seed'' + 0x0000000000269EC3</code>
<code>''result'' = 0x5D588B656C078965 × ''seed'' + 0x0000000000269EC3</code>


===Alternative pseudorandom number generator (ARNG)===
===Alternative pseudorandom number generator (ARNG)===
The [[Generation IV]] games also use a different algorithm to alternate, reroll, or modify a previously randomly generated value. The algorithm works in the same nature; however, the equation changes to:
The [[Generation IV]] games also use a different algorithm to alternate, reroll, or modify a previously randomly generated value. The algorithm works in the same nature; however, the equation changes to:


<code>''result'' = 0x6C078965 * seed + 0x00000001</code>
<code>''result'' = 0x6C078965 × seed + 0x00000001</code>


This algorithm is used for the following:
This algorithm is used for the following: