Random Functions in 4K, 8K

Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v2 n9 (Volume 2, Issue 9)
Date: September 1981
Pages: 9

Several readers have asked us for clarification of ZX80 random functions. This month we’ll compare RND (4K, 8K), RAND (8K), and RANDOMISE (4K).

All three functions in both ROMs make pseudo-random numbers. The ZX80 generates a long number sequence in memory, so long that the sequence appears random. Some functions allow you to tell the computer where in the sequence to start picking numbers. Otherwise, system variables determine start.

RND is probably the most confusing when translating from 4K to 8K ROM. In 4K, RND takes the form RND(X), where X is an integer. RND(X) yields a “random” integer (whole number) between 1 and X. In 8K, RND uses no X and picks decimal fractions between 0 and 1.

RAND Y sets the randomness of 8K RND. (That is, RAND Y will pick numbers with Y between 1 and 65535.) For instance, RAND 25 will give you the 25th number in the ZX80’s sequence. Each Y will give you the same “random” number between 0 and 1 in 8K every time.

RANDOMISE has two different functions in 4K. RANDOMISE N points to the number sequence the same way as RAND Y does for 8K. However, RANDOMISE (no N, or N=0) picks numbers depending on how long the machine has been on.

RANDOMISE N = RAND N, N <>0
RANDOMISE.RANDOMISE 0 = RAND 0