How does RND effect RAND?
How does RND effect RAND?
If I peek the RAND variable after a refresh, it contains the number zero. If I use RND once, the RAND variable now contains 74. If I use RND again the RAND variable now contains 5624, then 28652 etc. This makes me realise I don’t really understand how RND works. I thought it stepped through a pseudo random sequence in sequential order. Can anyone explain it to me?
- 1024MAK
- Posts: 5527
- Joined: Mon Sep 26, 2011 10:56 am
- Location: Looking forward to summer in Somerset, UK...
- Contact:
Re: How does RND effect RAND?
Do you mean 16434 (0x4032) "SEED", the Random Number Seed system variable?
Have a read of chapter 5 in the ZX81 BASIC programming book.
The system variable is updated after each use of RND, but as you have seen, it's not in a sequential sequence. Rather, it's a new seed value derived from RND ready for the next RND.
If you multiply the result of RND by 65536, it should be the same as SEED.
Mark
Have a read of chapter 5 in the ZX81 BASIC programming book.
The system variable is updated after each use of RND, but as you have seen, it's not in a sequential sequence. Rather, it's a new seed value derived from RND ready for the next RND.
If you multiply the result of RND by 65536, it should be the same as SEED.
Code: Select all
1 POKE 16434,0
2 POKE 16435,0
10 PRINT "BEFORE: ";PEEK 16434+256*PEEK 16435
20 LET R=RND
30 PRINT R;" ";R*65536
40 PRINT "AFTER: ";PEEK 16434+256*PEEK 16435
50 PRINT
60 INPUT A$
70 IF A$="" THEN GOTO 10
Mark
ZX81 Variations
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp
Standby alert 
There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb
Spring approaching...
ZX81 Chip Pin-outs
ZX81 Video Transistor Amp


There are four lights!
Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb

Spring approaching...
Re: How does RND effect RAND?
Ah, yes- so the RND numbers ARE in sequential order, but the SEEDS (RAND system variable (16434, 16435) are made random?
If I do this, it gives the actual RND sequential sequence:
10 Let X=1
20 RAND X
30 PRINT RND
40 LET X=X+1
50 GOTO 20
If I do this, it gives the actual RND sequential sequence:
10 Let X=1
20 RAND X
30 PRINT RND
40 LET X=X+1
50 GOTO 20