GBDK 2020 Docs
4.3.0
API Documentation for GBDK 2020
|
Go to the source code of this file.
Macros | |
#define | RAND_MAX 255 |
#define | RANDW_MAX 65535 |
Functions | |
void | initrand (uint16_t seed) OLDCALL |
uint8_t | rand (void) OLDCALL |
uint16_t | randw (void) OLDCALL |
void | initarand (uint16_t seed) OLDCALL |
uint8_t | arand (void) OLDCALL |
Variables | |
uint16_t | __rand_seed |
Random generator using the linear congruential method
#define RAND_MAX 255 |
#define RANDW_MAX 65535 |
void initrand | ( | uint16_t | seed | ) |
Initalise the pseudo-random number generator.
seed | The value for initializing the random number generator. |
The seed should be different each time, otherwise the same pseudo-random sequence will be generated.
One way to do this is sampling (DIV_REG) up to 2 times (high byte of seed value then the low byte) at variable, non-deterministic points in time (such as when the player presses buttons on the title screen or in a menu).
It only needs to be called once to be initialized.
uint8_t rand | ( | void | ) |
Returns a random byte (8 bit) value.
initrand() should be used to initialize the random number generator before using rand()
uint16_t randw | ( | void | ) |
Returns a random word (16 bit) value.
initrand() should be used to initialize the random number generator before using rand()
void initarand | ( | uint16_t | seed | ) |
Random generator using the linear lagged additive method
seed | The value for initializing the random number generator. |
Note: initarand() calls initrand() with the same seed value, and uses rand() to initialize the random generator.
uint8_t arand | ( | void | ) |
Returns a random number generated with the linear lagged additive method.
initarand() should be used to initialize the random number generator before using arand()
|
extern |
The random number seed is stored in __rand_seed and can be saved and restored if needed.