This program generates lottery number selections by picking six unique random integers in the range 1–44 and displaying them pre-sorted in ascending order. It produces ten labelled games (A–J) per screen and repeats until the user is satisfied, with options to copy the results to a printer using the COPY and LPRINT commands. The sort is implemented inline rather than with a subroutine: each new random number is inserted into the correct position in the sequence by cascading conditional assignments through variables A–F.
Program Structure
The program divides into four logical phases:
- Introduction screen (lines 5–100): splash text, flashing prompts, and a busy-wait keypress loop at line 100.
- Game generation loop (lines 105–590): initialises the game-letter array, then iterates
K=1 TO 10, generating and sorting six unique numbers per game. - Post-display options (lines 610–670): COPY/LPRINT for hard copy, and a STOP/CONTINUE branch.
- Quit sequence (lines 675–1035): a secondary confirmation, followed by
NEWat line 1035 which destroys the program. The unused line 1010 contains aSAVE "lottery" LINE 1for re-saving the tape.
The subroutine at line 1000–1005 is the only true subroutine: it simply wraps LET x=INT(RND*44)+1 and RETURN, centralising the random number generation.
Sorting Technique — Cascading Insertion
Rather than using an array and a sort loop, the program keeps six scalar variables A–F and inserts each new value into its correct sorted position using cascading conditional assignments. The logic for inserting the nth number checks each of the n−1 interval conditions in sequence and shifts values right. For example, inserting the fourth number X into the sorted triple A≤B≤C:
- If
X<A: shift D←C, C←B, B←A, A←X (four separate IF lines, 280–295) - If
A<X<B: shift D←C, C←B, B←X (lines 300–310) - If
B<X<C: shift D←C, C←X (lines 315–320) - If
X>C: D already holds the correct value from line 275.
This pattern grows with each additional number; inserting the sixth value F requires the longest block (lines 425–520). Because each condition is tested as a separate IF statement sharing the same X, the cascade works correctly only because BASIC evaluates them sequentially and each assignment changes the variables used in subsequent tests — the logic is therefore order-dependent and subtly fragile if lines were reordered.
Key BASIC Idioms
| Idiom | Location | Purpose |
|---|---|---|
IF INKEY$="" THEN GO TO 100 | Line 100 | Busy-wait for any keypress without INPUT |
DIM G$(10,1) populated with single letters | Lines 125–175 | String array used as a label look-up for game identifiers A–J |
LET L=L+2 inside the FOR loop | Line 185 | Manual row counter stepping by 2, giving each game its own print row |
IF L=20 THEN GO TO 610 | Line 595 | Detects when all 10 games have been printed (rows 2,4…20) and exits the outer loop |
Dual IF A<=9 / IF A>=10 column adjustment | Lines 530–585 | Right-aligns single and double-digit numbers by printing at different column positions |
FLASH 1:…:FLASH 0 wrapping headings | Multiple | Highlights key prompts without affecting surrounding text |
Pagination Logic
The screen can only show 10 games at two rows each plus headers, filling rows 2–20. The variable L starts at 0 and increments by 2 each iteration of the FOR K loop, so it reaches 20 after the tenth game. Line 595 detects L=20 and branches to the print/stop options; otherwise line 600 jumps back to line 125, which re-initialises L=0 (via line 115 is not revisited — L is not reset here; line 600 jumps to 125, which only re-dims G$ and resets labels, but L is still 20 from the previous pass). This is a latent bug: after the first set of 10 games, jumping to line 125 does not reset L, so L immediately becomes 22 in the next iteration and the L=20 check at line 595 is never true again, causing the loop to run past row 20 and scroll off-screen. The correct fix would be to jump to line 115 instead of 125, or add LET L=0 at line 125.
Printer and Quit Handling
COPY at line 635 sends a screen dump to the printer. The LPRINT at line 640 appends a separator line of dashes and a blank line below the dump. The destructive quit at lines 1020–1035 prints a warning message, pauses, then executes NEW; this is an intentional copy-protection/dramatic-exit device consistent with the copyright REM at line 5. The SAVE "lottery" LINE 1 at line 1010 is never called by the running program — it exists solely so the author can manually GO TO 1010 to re-save the tape.
Content
Source Code
5 REM RESET 1984 Rights Reserved Program by Michael J. Kudelka
10 REM PROGRAM "lottery"
20 PRINT AT 0,0;"The computer selects lotterynumbers 1-44 at random for you."
30 PRINT AT 3,0;"Each game consists of 6 numbers.One set of 10 games A-J islisted on the screen with anoption to copy on the printer."
40 PRINT AT 8,0;" "
50 FLASH 1: PRINT AT 8,13;"OPTIONS": FLASH 0
60 PRINT AT 10,0;"At the bottom of the screenafter the 10 games are listedyou will be given two options."
70 PRINT AT 14,0;"Option 1. Copy? (y)es or (n)o.": PRINT AT 15,0;"_________"
80 PRINT AT 17,0;"Option 2. Stop? (y)es or (n)o.": PRINT AT 18,0;"_________"
90 PRINT AT 20,0;"████ ████"
91 PRINT AT 21,0;" "
95 FLASH 1: PRINT AT 20,5;"PRESS ANY KEY TO START": FLASH 0
100 IF INKEY$="" THEN GO TO 100
105 CLS
115 LET L=0
120 PRINT AT 0,2;"LOTTERY NUMBERS FOR TEN GAMES"
125 DIM G$(10,1)
130 LET G$(1)="A"
135 LET G$(2)="B"
140 LET G$(3)="C"
145 LET G$(4)="D"
150 LET G$(5)="E"
155 LET G$(6)="F"
160 LET G$(7)="G"
165 LET G$(8)="H"
170 LET G$(9)="I"
175 LET G$(10)="J"
180 FOR K=1 TO 10
185 LET L=L+2
190 GO SUB 1000
195 LET A=X
200 GO SUB 1000
205 IF X=A THEN GO TO 200
210 LET B=X
215 IF X<A THEN LET B=A
220 IF X<A THEN LET A=X
225 GO SUB 1000
230 IF X=A OR X=B THEN GO TO 225
235 LET C=X
240 IF X<A THEN LET C=B
245 IF X<A THEN LET B=A
250 IF X<A THEN LET A=X
255 IF X>A AND X<B THEN LET C=B
260 IF X>A AND X<B THEN LET B=X
265 GO SUB 1000
270 IF X=A OR X=B OR X=C THEN GO TO 265
275 LET D=X
280 IF X<A THEN LET D=C
285 IF X<A THEN LET C=B
290 IF X<A THEN LET B=A
295 IF X<A THEN LET A=X
300 IF X>A AND X<B THEN LET D=C
305 IF X>A AND X<B THEN LET C=B
310 IF X>A AND X<B THEN LET B=X
315 IF X>B AND X<C THEN LET D=C
320 IF X>B AND X<C THEN LET C=X
325 GO SUB 1000
330 IF X=A OR X=B OR X=C OR X=D THEN GO TO 325
335 LET E=X
340 IF X<A THEN LET E=D
345 IF X<A THEN LET D=C
350 IF X<A THEN LET C=B
355 IF X<A THEN LET B=A
360 IF X<A THEN LET A=X
365 IF X>A AND X<B THEN LET E=D
370 IF X>A AND X<B THEN LET D=C
375 IF X>A AND X<B THEN LET C=B
380 IF X>A AND X<B THEN LET B=X
385 IF X>B AND X<C THEN LET E=D
390 IF X>B AND X<C THEN LET D=C
395 IF X>B AND X<C THEN LET C=X
400 IF X>C AND X<D THEN LET E=D
405 IF X>C AND X<D THEN LET D=X
410 GO SUB 1000
415 IF X=A OR X=B OR X=C OR X=D OR X=E THEN GO TO 410
420 LET F=X
425 IF X<A THEN LET F=E
430 IF X<A THEN LET E=D
435 IF X<A THEN LET D=C
440 IF X<A THEN LET C=B
445 IF X<A THEN LET B=A
450 IF X<A THEN LET A=X
455 IF X>A AND X<B THEN LET F=E
460 IF X>A AND X<B THEN LET E=D
465 IF X>A AND X<B THEN LET D=C
470 IF X>A AND X<B THEN LET C=B
475 IF X>A AND X<B THEN LET B=X
480 IF X>B AND X<C THEN LET F=E
485 IF X>B AND X<C THEN LET E=D
490 IF X>B AND X<C THEN LET D=C
495 IF X>B AND X<C THEN LET C=X
500 IF X>C AND X<D THEN LET F=E
505 IF X>C AND X<D THEN LET E=D
510 IF X>C AND X<D THEN LET D=X
515 IF X>D AND X<E THEN LET F=E
520 IF X>D AND X<E THEN LET E=X
525 PRINT AT L,0;"Game ";G$(K)
530 IF A<=9 THEN PRINT AT L,11;A
535 IF A>=10 THEN PRINT AT L,10;A
540 IF B<=9 THEN PRINT AT L,15;B
545 IF B>=10 THEN PRINT AT L,14;B
550 IF C<=9 THEN PRINT AT L,19;C
555 IF C>=10 THEN PRINT AT L,18;C
560 IF D<=9 THEN PRINT AT L,23;D
565 IF D>=10 THEN PRINT AT L,22;D
570 IF E<=9 THEN PRINT AT L,27;E
575 IF E>=10 THEN PRINT AT L,26;E
580 IF F<=9 THEN PRINT AT L,31;F
585 IF F>=10 THEN PRINT AT L,30;F
590 NEXT K
595 IF L=20 THEN GO TO 610
600 GO TO 125
610 FLASH 1: PRINT AT 21,0;"COPY?": FLASH 0: PRINT AT 21,6;"Press (y) or (n) and ENTER"
615 INPUT P$
620 IF p$="y" THEN GO TO 630
625 IF P$="n" THEN GO TO 655
630 PRINT AT 21,0;" "
635 COPY
640 LPRINT "--------------------------------"
650 LPRINT
655 FLASH 1: PRINT AT 21,0;"STOP?": FLASH 0: PRINT AT 21,6;"Press (y) or (n) and ENTER"
660 INPUT S$
665 IF S$="y" THEN GO TO 675
670 IF S$="n" THEN GO TO 105
675 PRINT AT 21,0;"█████████████ █████████████": FLASH 1: PRINT AT 21,14;"STOP": FLASH 0
680 PAUSE 200
690 FLASH 1: PRINT AT 21,0;"QUIT?": FLASH 0: PRINT AT 21,5;" Press (y) or (n) and ENTER"
700 INPUT T$
705 IF T$="y" THEN GO TO 1020
710 IF T$="n" THEN CLS : GO TO 20
1000 LET x=INT (RND*44)+1
1005 RETURN
1010 SAVE "lottery" LINE 1
1015 GO TO 20
1020 CLS
1025 PRINT AT 2,0;"You have now destroyed this";AT 4,0;"program. If you wish to";AT 6,0;"continue, you must reload."
1030 PAUSE 1000
1035 NEW
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

