2068 Random Numbers

See all articles from CATS v3 n2
Author(s): M. S. Morris
Publication: CATS Newsletter
Pub Details: CATS v3 n2 (Volume 3, Issue 2)
Date: May 1985
Pages: 11

The RND function of the 2068 is implemented by means of a algorithm similar to many other random number generators in both large and small computers. This general class is called “congruential” generators; the 2068 falls in sub-class known as multiplicative generators. The 2068’s generator will produce exactly 65526 different numbers before starting to repeat the sequence.

At the Feb. CATS meeting, Roald Schrack distributed a handout which noted that a program of the form

  10 LET x=255*RND:LET y=175*RND
20 PLOT X,Y :GOTO 10

will produce a pattern of vertical stripes. This is in fact a characteristic of all congruential generators, arising from the fact that sucessive values produced by the generator have a definite relationship. The pattern can be somewhat scrambled by generating and throwing away a number between the generation of values for x and y. For most purposes the generator will be a very good approximation to a true random number generator.

Articles on random number genereration have appeared in recent issues of MICRO (June 1984, Oct. 1983), CALL-A.P.P.L.E. (Jan. 1983), CREATIVE COMPUTING (March 1982), and PC TECH J.(Aug.1984). The formula used in the 2068 is given in the user’s manual on page 226. Note that the system variable called SEED in the user manual always holds an integer between 0 and 65536. This number is incremented by 1 before being used to generate the next number, and the new number is decremented by 1 before being saved in SEED. At power-up, SEED will hold 0.

M. S. Morris

   5 REM this program demonstrates how the RND function of the 2068 works.An integer is stored in  system variable "SEED"
6 REM
10 LET z=PEEK 23670+256*PEEK 23671: REM this is the "seed"
12 LET z=z+1
20 LET a=75*z/65537
40 LET a=(a-INT a)*65537-1
50 PRINT a: REM a is the new value to be stored in SEED"
60 PRINT a/65536: REM this is value of RND
70 PRINT RND: REM confirm the calculation of RND
100 PRINT PEEK 23670+256*PEEK 23671: REM confirm that a is the new seed

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.