Setting random seed with INKEY$

78 views
Skip to first unread message

James Harland

unread,
Oct 22, 2025, 12:16:53 AMOct 22
to RC2014-Z80
I'm using my newly soldered RC 2014 Classic II over Minicom on a Linux box. Trying to generate a pseudo random number in BASIC which is not the same every time the RC2014 switches on.

I've read this thread, though I need to try out what is mentioned there. I'm not afraid of some machine code routines, I've got some experience on Sinclair machines.

I posted on retrocomputing stack exchange, and the person there recommended using an INKEY$ loop, but it seems that the BASIC never breaks out of such a loop. Is this an issue with using BASIC over a serial connection, I wonder?


Wayne Hortensius

unread,
Oct 22, 2025, 12:40:47 AMOct 22
to rc201...@googlegroups.com
James Harland wrote:

> I posted on retrocomputing stack exchange
> <https://retrocomputing.stackexchange.com/questions/32186/how-to-automatically-set-the-random-seed-in-microsoft-z80-basic/32189?noredirect=1#comment117898_32189>,
> and the person there recommended using an INKEY$ loop, but it seems
> that the BASIC never breaks out of such a loop. Is this an issue with
> using BASIC over a serial connection, I wonder?

If we're talking Microsoft BASIC-80, no. I just PuTTY'd into my CP/M
box in the basement that has its console redirected to the TTY port and
hooked up to a Wifi modem. So the console is connected to a serial
port. Then I did the following:

A4:DOC>>mbasic
BASIC-80 Rev. 5.21
[CP/M Version]
Copyright 1977-1981 (C) by Microsoft
Created: 28-Jul-81
32824 Bytes free
Ok
100 REM Display title screen
110 A$ = INKEY$:IF LEN(A$)<>0 THEN 110
120 PRINT "Press any key to continue"
130 SEED% = 1234
140 SEED% = SEED% + 1
150 A$=INKEY$:IF LEN(A$)=0 THEN 140
160 RANDOMIZE SEED%
170 PRINT SEED%,RND
run
Press any key to continue
13024 .864285
Ok
run
Press any key to continue
15321 .603936
Ok

James Harland

unread,
Oct 22, 2025, 1:07:06 AMOct 22
to RC2014-Z80
That's cool, I wonder why it doesn't work on the Z80 BASIC 4.7b via Minicom.

James Harland

unread,
Oct 22, 2025, 9:31:27 AMOct 22
to RC2014-Z80
I dont' know, there's something wrong with INKEY$ on my machine, or my setup. Even if I do something like:

10 B$="f"
20 A$ = INKEY$
30 LET B$ = A$ +B$
40 GOTO 10

Then run it and type away at the keyboard, when I escape out b$ is still "f"

Robert Price

unread,
Oct 22, 2025, 10:07:08 AMOct 22
to rc201...@googlegroups.com
Hi James,

Shouldn't line 20 use the INPUT statement to read from the keyboard? I think INKEY$ is just a variable name in this version of BASIC.

20 INPUT A$

Rob

--
You received this message because you are subscribed to the Google Groups "RC2014-Z80" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rc2014-z80+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/rc2014-z80/8421b609-aad0-4ebb-93d4-5220ae878519n%40googlegroups.com.

James Harland

unread,
Oct 22, 2025, 10:29:43 AMOct 22
to RC2014-Z80
Hi Robert,

Thanks for your reply I was going kind of crazy with INKEY$ - that explains it if it's not implemented in this BASIC! I thought it would throw an error, but it seems that unassigned variables are just emtpty strings, which would explain everything. It also seems that the BASIC that ships with the CP/M version of the RS 2014 is a different version that does support INKEY$ which explains Wayne's reply.

I previously was using INPUT to get a seed value from the user, but I wanted to somehow do it 'randomly'. Now I've managed to do what I want by modifying Scott Lawrence's program from 2017, and using the contents of the r registers as a seed value.

    100 REM Poking in the 'random' seed program
    110 read op
    120 if op = 999 then goto 200
    130 poke mb, op
    140 let mb = mb + 1
    150 goto 110
    200 REM == JP start address (c3 00 f8) jp f800 ==
    210 mb = &H8048
    220 poke mb, &HC3
    230 poke mb+1, &H00
    240 poke mb+2, &HF8
    260 seed = usr(0)
    270 x = rnd(-seed)
    280 print int(rnd(1)*6)+1
    290 end
    9000 REM == program ==
    9001 DATA 237, 95, 60, 237, 79, 71, 175, 195, 125, 17
    9003 DATA 999

Thanks for your reply, I couldn't figure out what the matter was!

James

James Harland

unread,
Oct 22, 2025, 12:37:12 PMOct 22
to RC2014-Z80
Just for posterity, here is the correct version of the above, with the necessary setting of address $8000 to start poking, and the simplified machine code routine:

20 REM == poke at 0xF800 ==
30 let mb=&HF800
100 REM Poking in the program

110 read op
120 if op = 999 then goto 200
130 poke mb, op
140 let mb = mb + 1
150 goto 110
200 REM == JP start address (c3 00 f8) jp f800 ==
210 mb = &H8048
220 poke mb, &HC3
230 poke mb+1, &H00
240 poke mb+2, &HF8
260 seed = usr(0)
270 x = rnd(-seed)
280 print int(rnd(1)*6)+1
290 end
9000 REM == program ==
9001 DATA 237, 95, 71, 175, 195, 125, 17
9003 DATA 999

Reply all
Reply to author
Forward
0 new messages