On this page:
randomize
rnd
timer

3.9 Random Numbers🔗ℹ

Heresy’s random number generator operates slightly differently to traditional BASIC’s, in order to offer a more functional approach. Rather than defining a single global seed which the RND function then refers to, Heresy’s randomize returns a "generator" function with a given seed, allowing one to name and seed as many generators as one needs, though for practical purposes a default RND is still provided which is automatically created and seeded with a derivation of the current time in milliseconds. Heresy’s RNG employs a fairly strong 64ish-bit Xorshift* algorithm, though no guarantees are offered as to its cryptographic security.

procedure

(randomize [seed])  fn?

  seed : any/c = timer
Returns a new generator function initialized with seed, which is first passed through equal-hash-code. If no seed is provided, defaults to timer.

procedure

(rnd)  number?

A pre-defined generator which returns a random number between 0 and 1, exclusive, seeded by timer.

value

timer : number?

A special internal variable which contains the current time in milliseconds.