In the Z-machine, numbers are usually stored in 2 bytes (in the form most-significant-byte first, then least-significant) and hold any value in the range $0000 to $ffff (0 to 65535 decimal).
The author suggests the following algorithm:
1. In "random" mode, the generator uses the host computer's clock to obtain a random sequence of bits.
2. In "predictable" mode, the generator should store the seed value S. If S < 1000 it should then internally generate
1, 2, 3, ..., S, 1, 2, 3, ..., S, 1, ...
so that random n produces the next entry in this sequence modulo n. If S >= 1000 then S is used as a seed in a standard seeded random-number generator.
(The rising sequence is useful for testing, since it will produce all possible values in sequence. On the other hand, a seeded but fairly random generator is useful for testing entire scripts.)
Note that version 0.2 of this standard mistakenly asserted that division and remainder are unsigned, a myth deriving from a bug in Zip. Infocom's interpreters do sign division (this is relied on when calculating pizza cooking times for the microwave oven in 'The Lurking Horror'). Here are some correct Z-machine calculations:
-11 / 2 = -5 -11 / -2 = 5 11 / -2 = -5 -13 % 5 = -3 13 % -5 = 3 -13 % -5 = -3
Section 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 / 12 / 13 / 14 / 15 / 16
Appendix A / B / C / D / E / F