08-05-2018, 06:21 PM
If I write this simple program:
a number between 0 and 40 will be shown at every pressing of ENTER.
However, inside of a larger program, this instruction:
always returns 38 when executed.
Also, the RND of the first example always returns exactly the same sequence when started afresh, at least under emulation (Spectaculator): 9, 34, 15, 7, 16, 25, 13, 37, 7, 24, 19 etc.
In the past I used a simple routine (by John Connolly) to generate random numbers. Here it is, modified to let it return values from 0 to 31:
When placed in a ZX-Basic listing as a subroutine, it will always return the first value. The only way to make it work is to assemble it elsewhere and call it from within ZX-BASIC with the usual RANDOMIZE USR call, then assign the PEEK [address] to a variable.
Code:
DIM u as UBYTE
10 let u =rnd*40
print u
pause 0
if code inkey$=13 then stop
40 goto 10
However, inside of a larger program, this instruction:
Code:
DIM x AS UBYTE
...
x = rnd*40
Also, the RND of the first example always returns exactly the same sequence when started afresh, at least under emulation (Spectaculator): 9, 34, 15, 7, 16, 25, 13, 37, 7, 24, 19 etc.
In the past I used a simple routine (by John Connolly) to generate random numbers. Here it is, modified to let it return values from 0 to 31:
Code:
LD A,R
AND %00011111
LD (address),A