On this page:

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.


(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.


(rnd)  number?

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


timer : number?

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