OFFSET
1,2
COMMENTS
The ZX81 had a congruential random number generator with the hardcoded values: x <- (75*x + 74) mod 65537.
This sequence starts with x = 1. The ZX81 had the option to start with a hardware counter.
The sequence has period 2^16. - Rémy Sigrist, Oct 20 2022
The ZX81 returned these values divided by 65536 as floating-point numbers, however, the seed was set as an integer using RAND (or RANDOMIZE on the ZX Spectrum). To produce the sequence as given here on the ZX81, set the seed with RAND 25340 (the last value in the period before it returns to 1), then print successive values with PRINT 65536*RND. On the ZX81, the current seed was stored in memory locations 16343 and 16384, and could be retrieved with PRINT 256*PEEK 16435+PEEK 16434 (which is equivalent to PRINT 65536*RND, but does not trigger stepping to the next value). - Sean A. Irvine, May 08 2025
LINKS
Jianing Song, Table of n, a(n) for n = 1..65536
B. D. Ripley, Computer Generation of Random Variables: A Tutorial, International Statistical Review, 51 (1983), 301-309.
W. E. Sharp and Carter Bays, A review of portable random number generators, Computers and Geosciences, 18, 1 (1982), 79-87.
Wikipedia, Linear congruential generator.
FORMULA
a(n) = (75*a(n-1) + 74) mod 65537, a(1) = 1.
a(n + 2^16) = a(n). - Rémy Sigrist, Oct 20 2022
a(n) = (2*75^(n-1) - 1) mod 65537. - Kevin Ryde, Oct 20 2022
a(n) = a(n-1) - a(n-32768) + a(n-32769) for n > 32769. - Ray Chandler, Aug 03 2023
MATHEMATICA
NestList[Mod[75*# + 74, 65537] &, 1, 50] (* Paolo Xausa, Oct 03 2024 *)
PROG
(R)
x <- 1
nxt <- function(x) (75*x + 74) %% 65537
for (t in 1:1000) {
cat(sprintf('%i, ', x))
x <- nxt(x)
}
(PARI) my(c=Mod(75, 65537)); a(n) = lift(2*c^(n-1) - 1); \\ Kevin Ryde, Oct 22 2022
(Python)
def a(n): return (2*pow(75, n-1, 65537) - 1)%65537
print([a(n) for n in range(1, 43)]) # Michael S. Branicky, Oct 23 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Jacques Basaldúa, Oct 19 2022
STATUS
approved
