GBDK 2020 Docs
API Documentation for GBDK 2020
rand.h File Reference
#include <types.h>

Go to the source code of this file.

Functions

void initrand (UINT16 seed) NONBANKED
 
INT8 rand (void)
 
UINT16 randw (void)
 
void initarand (UINT16 seed)
 
INT8 arand (void)
 

Detailed Description

Random generator using the linear congruential method

Author
Luc Van den Borre

Function Documentation

◆ initrand()

void initrand ( UINT16  seed)

Initalise the pseudo-random number generator.

Parameters
seedThe 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, buy may be called again to re-initialize with the same or a different seed.

See also
rand(), randw()

◆ rand()

INT8 rand ( void  )

Returns a random byte (8 bit) value.

initrand() should be used to initialize the random number generator before using rand()

◆ randw()

UINT16 randw ( void  )

Returns a random word (16 bit) value.

initrand() should be used to initialize the random number generator before using rand()

◆ initarand()

void initarand ( UINT16  seed)

Random generator using the linear lagged additive method

Parameters
seedThe value for initializing the random number generator.

Note: initarand() calls initrand() with the same seed value, and uses rand() to initialize the random generator.

See also
initrand() for suggestions about seed values, arand()

◆ arand()

INT8 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()