--- title: "Lottery" id: 64712 type: "computer_media" slug: "lottery" url: "http://localhost/computer_media/lottery/" markdown_url: "http://localhost/computer_media/lottery.md" published_at: "2026-03-07T00:09:54+00:00" modified_at: "2026-03-30T21:43:31+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/03/lottery.png" excerpt: "A lottery picker that generates ten sorted six-number selections and uses a clever cascading-insertion sort entirely in plain BASIC variables." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 2068" slug: "ts2068" taxonomy: "post_tag" url: "http://localhost/tag/ts2068/" model: - name: "Timex/Sinclair 2068" slug: "ts-2068" taxonomy: "model" url: "http://localhost/model/ts-2068/" indiv: - name: "Michael Kudelka" slug: "michael-kudelka" taxonomy: "indiv" url: "http://localhost/indiv/michael-kudelka/" genre: - name: "Entertainment" slug: "entertainment" taxonomy: "genre" url: "http://localhost/type/entertainment/" media_type: "Program" programmers: - name: "Michael Kudelka" slug: "michael-kudelka" taxonomy: "indiv" url: "http://localhost/indiv/michael-kudelka/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Lottery%281984%29%28Michael%20J.%20Kudelka%29%28TS2068%29%28US%29%28Programs%29.zip" mediadate: "1984" images: - url: "http://localhost/wp-content/uploads/2026/03/lottery.png" - url: "http://localhost/wp-content/uploads/2026/03/Lottery-scaled.jpg" article_media: - id: 39170 title: "The Fame & The Glory" type: "article" url: "http://localhost/article/the-fame-the-glory/" media_type_tags: "Entertainment" --- 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: 1. **Introduction screen** (lines 5–100): splash text, flashing prompts, and a busy-wait keypress loop at line 100. 2. **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. 3. **Post-display options** (lines 610–670): COPY/LPRINT for hard copy, and a STOP/CONTINUE branch. 4. **Quit sequence** (lines 675–1035): a secondary confirmation, followed by `NEW` at line 1035 which destroys the program. The unused line 1010 contains a `SAVE "lottery" LINE 1` for 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 *n*th 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 `XC`: 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. ## 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 XA AND XA AND XA AND XA AND XA AND XB AND XB AND XA AND XA AND XA AND XA AND XB AND XB AND XB AND XC AND XC AND XA AND XA AND XA AND XA AND XA AND XB AND XB AND XB AND XB AND XC AND XC AND XC AND XD AND XD AND X=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 ```