Skip to the content.

random.fs (lib)

The random.fs library contains very basic xorshift random number generator (RNG).

Usage

Initialise the lib with by setting the seed variable to a non-zero value first. This can be done in a couple of ways:

require random.fs

\ for some games using a constant value might be good enough
: main
  1234 seed ! ;

\ common pattern in Forth, but essentially a constant in gbforth
: main
  here seed ! ;

\ use the divider register (from gbhw.fs)
: main
  rDIV c@ 1 max seed ! ;

Word Index

random ( n – n )

Generate a random number between 0 and n (exclusive).

rnd ( – n )

Generate a random number.

shuffle ( a-addr u – )

Shuffles u cells starting from a-addr.

cshuffle ( c-addr u – )

Shuffles u chars starting from c-addr.