--- title: "Ticket Drawer" id: 57001 type: "computer_media" slug: "ticket-drawer" url: "http://localhost/computer_media/ticket-drawer/" markdown_url: "http://localhost/computer_media/ticket-drawer.md" published_at: "2024-10-02T07:21:28+00:00" modified_at: "2026-03-30T21:20:19+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/25_Tkt.png" excerpt: "A BASIC raffle drawer picks random winners from a numbered ticket range — but a subtle variable bug means the range calculation may never work as intended." 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 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Entertainment" slug: "entertainment" taxonomy: "genre" url: "http://localhost/type/entertainment/" media_contents: - id: 56732 title: "Timex Sinclair Public Domain Library Tape 1001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1001/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/25_Tkt.png" media_type_tags: "Entertainment" --- # Ticket Drawer This program simulates a raffle ticket draw by accepting a range of ticket numbers and a desired number of winners, then using the RND function to select random ticket numbers within that range. The lottery draw loop at lines 210–264 generates W random values scaled to the ticket range and prints each winner with a decorative arrow prefix. The program includes a guard at line 130 that redirects to an error message if more winners are requested than the total number of tickets sold. A notable structural issue exists: the variable H is referenced in line 90 to compute the range E, but the highest ticket number entered at line 71 is stored in B (overwriting the lowest ticket number), meaning H is never actually assigned. *** ## Program Analysis ### Program Structure The program is divided into a loose sequence of phases: setup and input collection (lines 1–80), range and winner-count validation (lines 90–120), the draw output loop (lines 140–264), and an error branch for invalid winner counts (lines 268–272). Lines 1–4 are REM comments documenting constraints. The program ends with `STOP` at line 266 under normal flow, or falls through to the error message block around line 269. ### Variable Usage and a Key Bug The most significant anomaly is in the handling of the ticket range. At line 21 the lowest ticket number is read into `B`, and at line 71 the highest ticket number is also read into `B`, overwriting the lowest value. Line 90 then computes `E=H-B+1`, but `H` is never assigned anywhere in the program — it will be zero by default — making the range `E` always equal to `1-B` (i.e. a negative or near-zero number). The intended variable for the highest ticket was almost certainly `H` at line 71, and the lowest should have been stored in a different variable (e.g. `L`). ### Notable Techniques - The winning ticket number is computed as `Z+B-1` at line 262, intended to map a random value in `[0, E]` back to the actual ticket number range starting at `B`. This logic is correct in principle, but depends on the broken range variable `E` and the overwritten `B`. - The singular/plural branch at lines 182–185 checks `IF W>1` to print either “TICKET IS” or “TICKETS ARE”, a simple but effective grammatical guard. - Lines 12–13 define a `FOR` loop with `RND*(32767)` that is never closed with a `NEXT` — the loop variable `I` and value `J` are computed but never used, and the loop body has no matching `NEXT I`. This is likely dead or vestigial code. - The guard at line 91 checks `IF E<32767 THEN GOTO 110`, intending to skip the “TOO MANY TICKETS” message when within range, but the logic is inverted: it should only print the error when `E>=32767`. Because the branch skips to line 110 when the condition is true, the error message at line 100 is only reached when `E>=32767`, which is actually correct flow — but the message at line 100 has no `GOTO` to bypass line 110, so execution continues into the winner-count prompt regardless of the error. ### Variable Summary | Variable | Intended Purpose | Actual State | | --- | --- | --- | | `N` | Initial loop count (lines 12–13), then reused as winner index (line 210) | Reused — earlier value lost | | `J` | Random value in setup loop | Computed but never used | | `B` | Lowest ticket number | Overwritten with highest at line 71 | | `H` | Highest ticket number | Never assigned; defaults to 0 | | `E` | Total ticket count (range) | Incorrectly calculated due to above | | `W` | Number of winners requested | Correctly used | | `Z` | Random winner offset | Used correctly in draw loop | ### Flow Anomalies - Lines 12–13 begin a `FOR` loop that is never terminated with `NEXT I`; the loop body contains only a single `LET J=RND*(32767)` that is unused. - Line 100 prints an error but does not halt or branch away, so the program continues to line 110 regardless. - Line 268 (`CLS`) is only reachable if something branches to it, but the `GOTO 269` at line 130 skips it entirely, meaning the screen is never cleared before the error message. ## Source Code ``` 1 REM AUTO TICKET DRAWER 2 REM PICK WINNERS 3 REM NO MORE THAN 32767 SOLD 4 REM TICKET NOS 999999 AND OVER 5 PRINT TAB (10);"AUTO TICKET DRAW" 10 PRINT "ENTER A NUMBER FROM 1 TO 100" 11 INPUT N 12 FOR I=1 TO N 13 LET J=RND *(32767) 20 PRINT "THE LOWEST TICKET NUMBER IS " 21 INPUT B 50 PRINT 70 PRINT "THE HIGHEST TICKET NUMBER IS " 71 INPUT B 80 PRINT 90 LET E=H-B+1 91 IF E<32767 THEN GOTO 110 100 PRINT "TOO MANY TICKETS SOLD--" 110 PRINT "HOW MANY WINNERS DO YOU WANT?" 111 INPUT W 120 CLS 130 IF W>E THEN GOTO 269 140 PRINT 141 PRINT 142 PRINT 143 PRINT 180 PRINT "AND THE WINNING "; 182 IF W>1 THEN GOTO 185 183 PRINT "TICKET IS " 184 GOTO 200 185 PRINT "TICKETS ARE" 200 PRINT 210 FOR N=1 TO W 220 LET Z=RND*E 260 PRINT 262 PRINT TAB (12);">----->>> ";Z+B-1 264 NEXT N 266 STOP 268 CLS 269 PRINT 270 PRINT TAB (8);"YOU CANT HAVE MORE WINNERS THAN "; 272 PRINT "ENTRIES--DUMMY--" 300 SAVE "1002%5" 310 LIST ```