Package for numba @jitclass implementations (optionally uncompiled but with integers and arrays handled by numpy) of the Pseudo-Random Number Generators used in the Pokemon series
Contents are heavily based on implementations found in PokéFinder
numba-pokemon-prngs can be installed via pip with the following command
pip install "numba-pokemon-prngs[numba] @ git+https://github.com/Lincoln-LM/numba_pokemon_prngs"
or without numba support
pip install "numba-pokemon-prngs @ git+https://github.com/Lincoln-LM/numba_pokemon_prngs"
if numba is not detected, either by not being installed or for some other reason, numba-pokemon-prngs will default to relying only on numpy (as specified in compilation.py, and will log a warning unless the environment variable NPP_USE_NUMBA
is set to "FALSE" (or any value other than "TRUE").
This environment variable can additionally be used to trigger numba-less mode even when numba is installed.
additionally wheels for the latest commit are provided for direct installation at https://github.com/Lincoln-LM/numba_pokemon_prngs/releases/tag/latest
and can be installed to micropip for pyodide via
micropip.install("numba_pokemon_prngs-0.1.0-py3-none-any.whl")
after pulling the latest build from https://github.com/Lincoln-LM/numba_pokemon_prngs/releases/download/latest/numba_pokemon_prngs-0.1.0-py3-none-any.whl
Name | Description | Parameters | Additional Info | |
---|---|---|---|---|
LCRNG32 | ||||
PokeRNG | Standard PRNG for Gen 3/4 Pokemon games | Add: 0x6073, Mult: 0x41C64E6D | Supports modulo and reciprocal division random distribution | |
ARNG | Alternate Standard PRNG for Pokemon games | Add: 0x1, Mult: 0x6C078965 | Supports modulo random distribution | |
XDRNG | Standard PRNG for Gamecube Pokemon games | Add: 0x269EC3, Mult: 0x343FD | Supports modulo random distribution | |
LCRNG64 | ||||
BWRNG | Standard PRNG for Gen 5 Pokemon games | Add: 0x269EC3, Mult: 0x5D588B656C078965 | Supports multiplication-shift random distribution | |
MT | ||||
Mersenne Twister | Secondary PRNG for Gen 4/5 games, primary in Gen 6 | MT19937: init_mult = 0x6C078965 (w,n,m,r) = (32,624,397,31) a = 0x9908B0DF (u, d) = (11,0xFFFFFFFF) (s,b) = (7,0x9D2C5680) (t,c) = (15, 0xEFC60000) l = 18 |
||
SIMD-oriented Fast Mersenne Twister | Primary PRNG for Gen 7 | SFMT19937: init_mult = 0x6C078965 POS1 = 488 SL1 = 18 SL2 = 8 SR1 = 11 SR2 = 8 MASK = (0xDFFFFFEF,0xDDFECB7F,0xBFFAFFFF,0xBFFFFFF6) PARITY = (0x1,0x0,0x0,0x13C9E684) |
||
TinyMT | Secondary PRNG for Gen 6/7 | mat1 = 0x8F7011EE mat2 = 0xFC78FF1F tmat = 0x3793FDFF init_mult = 0x6C078965 |
||
Xorshift | ||||
Xoroshiro128+ w/Rejection Sampling | PRNG used in LGPE/SWSH/PLA/SV | s1_const = 0x82A2B175229D6A5B s0_rotl = 24 s1_shl = 16 s1_rotl = 37 |
Rejection sampling works by truncating the bits of a 64-bit rand only up to the most significant bit of the "maximum value," continuously generating random numbers this way until one is below the maximum. | |
Xoroshiro128+ w/Splitmix64 Seeding | Secondary PRNG used in BDSP | s0_rotl = 24 s1_shl = 16 s1_rotl = 37 splitmix_increment = 0x9E3779B97F4A7C15 splitmix_mul1 = 0xBF58476D1CE4E5B9 splitmix_shr1 = 30 splitmix_mul2 = 0x94D049BB133111EB splitmix_shr1 = 27 |
Splitmix64 in BDSP is only ever seeded with a u32, though re_init accepts u64. | |
Xorshift128 | Primary PRNG used in BDSP (Unity Engine) | t_shl1 = 11 t_shr1 = 8 s_shr = 19 |
Name | Description |
---|---|
RNGList | Cache for PRNG values to avoid expensive reinitialization |
SHA-1 | Hash function used for Gen 5 initial seed generation |