Ticket Drawer

This file is part of Timex Sinclair Public Domain Library Tape 1001 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000

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

VariableIntended PurposeActual State
NInitial loop count (lines 12–13), then reused as winner index (line 210)Reused — earlier value lost
JRandom value in setup loopComputed but never used
BLowest ticket numberOverwritten with highest at line 71
HHighest ticket numberNever assigned; defaults to 0
ETotal ticket count (range)Incorrectly calculated due to above
WNumber of winners requestedCorrectly used
ZRandom winner offsetUsed 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.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10001 – 10050.

Related Products

Related Articles

Related Content

Image Gallery

Ticket Drawer

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 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top