How would you use
RND
&
INT
to get a random whole number between 1 & 6, to represent the throw of
a die? (Answer:
INT
(
RND
*6) +1.)
5. Test this rule:
Suppose you choose a number between 1 & 872 & type
RAND
& then your number (&
NEWLINE
)
Then the next value of
RND
will be
(75 * (your number + 1) - 1)/65536
6. (For mathematicians only.)
Let p be a [large] prime, & let a be a primitive root modulo p.
Then if b
i
is the residue of a
i
modulo p (1 b
i
< p-1), the sequence
b
i
-1 / p - 1
is a cylindrical sequence of p-1 distinct numbers in the range 0 to 1 (excluding 1). By choosing a suitably,
these can be made to look fairly random.
65537 is a Mersenne prime, 2
16
-1. Use this & Gauss' law of quadratic reciprocity, to show that 75 is a
primitive root modulo 65537.
The ZX81 uses p=65537 & a=75, & stores some b
i
-1 in memory. The function RND involves replacing
b
i
-1 in memory by b
i+1
-1, & yielding the result (b
i+1
-1)/(p-1). RAND n (with 1 n 65535) makes b
i
equal
to n+1.
7.
INT
always rounds down. To round to the nearest integer, add 0.5 first. For instance,
Compare these with the answers you get when you don't add 0.5
8. Try
PRINT PI
,
PI
-3,
PI
-3.1,
PI
-3.14,
PI
-3.141
This shows how accurately the computer stores .
INT (2.9+0.5) = 3
INT (2.4+0.5) = 2
INT (-2.9+0.5) = -3
INT (-2.4+0.5) = -2