GBDK 2020 Docs
4.1.1
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 () OLDCALL |
uint16_t | randw () OLDCALL |
void | initarand (uint16_t seed) OLDCALL |
uint8_t | arand () 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.
The DIV Register (DIV_REG) is sometimes used as a seed, particularly if read at some variable point in time (such as when the player presses a button).
Only needs to be called once to initialize, but may be called again to re-initialize with the same or a different seed.
uint8_t rand | ( | ) |
Returns a random byte (8 bit) value.
initrand() should be used to initialize the random number generator before using rand()
uint16_t randw | ( | ) |
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 | ( | ) |
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.