Common functions to handle RNG manipulation. Using this interface has three goals: More...
#include <tonc.h>Go to the source code of this file.
Data Structures | |
| struct | RngInfo |
| Information to track and restore RNG state. More... | |
Enumerations | |
| enum | RngSequence { RNG_SEQ_CARD_SHUFFLE , RNG_SEQ_BLIND , RNG_SEQ_SHOP_ITEMS , RNG_SEQ_SKIP_TAGS , RNG_SEQ_JOKER_MISPRINT , RNG_SEQ_JOKER_RESERVED_PARKING , RNG_SEQ_JOKER_BUSINESS_CARD , RNG_SEQ_MISC , RNG_SEQ_MAX } |
| Keys to different independent RNG sequences. More... | |
Functions | |
| void | rng_init (void) |
| Starts counting CPU cycles, which will be used by rng_shuffle_seed to generate a more random seed. To be called once on game start. | |
| void | rng_update (void) |
| Accumulates CPU cycles for RNG seed generation, call exaclty once per frame. | |
| void | rng_set_seed (u32 seed) |
Set the rng seed to the chosen value, and reset the step counter to 0. The seed will be capped at MAX_BASE36 for compatibility with the Seed Input screen used to choose a seed for seeded runs. | |
| void | rng_shuffle_seed (void) |
| Sets a new randomized seed for the RNG using a source of entropy. | |
| u32 | rng_get_u32 (enum RngSequence key) |
| Get the next "randomly" generated number in the sequence corresponding to the given type. | |
| void | rng_restore (RngInfo info) |
Restore RNG info struct in the GameVariables. Sets the seed and restores the state for each independent sequence. | |
Common functions to handle RNG manipulation. Using this interface has three goals:
Definition in file random.h.
| enum RngSequence |
| u32 rng_get_u32 | ( | enum RngSequence | key | ) |
| void rng_init | ( | void | ) |
| void rng_restore | ( | RngInfo | info | ) |
Restore RNG info struct in the GameVariables. Sets the seed and restores the state for each independent sequence.
| info | RngInfo struct applied |
| void rng_set_seed | ( | u32 | seed | ) |
| void rng_shuffle_seed | ( | void | ) |
Sets a new randomized seed for the RNG using a source of entropy.
This needs to be called at least once before generating anything random but not on the very first cycle because it uses a CPU timer for entropy.
This would also be used to generate the new seed when starting a new non-player-seeded run
rng_init needs to have been called, so that the CPU profiling can provide entropy.