Random Sentences

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

This program is a random sentence generator that combines a subject, verb phrase, object, and predicate to produce humorous nonsense sentences. It picks from hard-coded comma-delimited strings for each grammatical role using a subroutine that counts comma separators to locate the Nth element. The random selection uses a two-stage approach: repeated RND calls inside a FOR loop (lines 1010–1030) attempt to “warm up” the random number generator before selecting one of five items per category. The main loop reseed mechanism at line 440 spins until INT(RND*100) equals exactly 5, then restarts the program with RUN, giving the appearance of an infinite stream of sentences. Output is managed with SCROLL calls to keep the display scrolling smoothly on the single-screen display.


Program Analysis

Program Structure

The program is divided into clearly commented sections, each handling one grammatical role in the generated sentence. Execution flows linearly through four phases before looping back via RUN:

  1. Lines 10–98: Initialisation — set M=1, A=0, scroll, and reseed RNG.
  2. Lines 99–220: Pick a subject from A$.
  3. Lines 200–220: Pick a verb/phrase from B$.
  4. Lines 299–340: Print “HIS ” then pick an object from C$.
  5. Lines 399–430: Pick a predicate from D$.
  6. Lines 439–450: Spin until INT(RND*100)=5, then RUN.

The subroutine at lines 1000–3030 handles all random selection. Lines 3040–3060 are unreachable dead code, never executed during normal program flow.

Data Representation

Each grammatical category is stored as a comma-delimited string. Every category contains exactly five elements, each terminated by a comma (including the last one). The working variable E$ is used as a parameter-passing mechanism — the caller loads E$ before invoking GOSUB 1000.

VariableRoleSample values
A$SubjectDENNIS, GREG, SCOTTY, KENNY, HAL, DONALD
B$Verb/phraseSPITS ALL OVER, HATES, KISSES, SITS ON, DROPS
C$ObjectTOENAILS, DOG, COMPUTER, T.V., PIZZA PAN
D$PredicateWHILE DRINKING BEER., LIKE A MANIAC., …

Note that A$ actually contains six names (DENNIS through DONALD) while the picker only selects from indices 1–5, making DONALD permanently unreachable.

Random Selection Subroutine

The subroutine entry at line 1000 calls RAND (no argument) to reseed from the system clock, then runs a loop (lines 1010–1030) that iterates a random number of times (1 to 10), each time computing a throwaway value X=(RND*65535). This is intended to “stir” the RNG state before the actual pick at line 1040: LET X=INT(RND*5)+1, selecting a value 1–5.

The search then scans E$ character by character (lines 1050–1070). Each comma encountered increments A (line 2000). When the comma count A equals the target X, control jumps to line 3000 which prints the substring from position M to N-1 (i.e., excluding the comma). The state variables M and A are reset to their initial values before returning.

Notable Techniques

  • Comma as delimiter: Rather than DATA/READ, items are packed into a single string and parsed by comma-scanning, saving memory on a RAM-constrained system.
  • Parameter passing via global: E$ acts as an informal parameter to the subroutine since BASIC lacks true local variables or argument passing.
  • RNG warm-up loop: The FOR I=1 TO INT(RND*10) loop with dummy RND calls attempts to add entropy, though on a deterministic LCG this has limited practical effect.
  • Reseed spin-wait: Line 440 busy-loops until INT(RND*100)=5 — a roughly 1-in-100 probability event — before calling RUN to restart the program with a new sentence. This introduces a variable delay between sentences.
  • SCROLL management: Explicit SCROLL calls at lines 30, 320, and 430 control display advancement, preventing the “scroll?” prompt from interrupting the output.

Bugs and Anomalies

  • Six subjects, only five reachable: A$ has six comma-separated names, but X is always 1–5, so “DONALD” is never selected.
  • Unreachable dead code: Lines 3040 (CLEAR), 3050 (SAVE "1029%5"), and 3060 (RUN) follow a GOTO 1080 at line 3030 and can never be reached during normal execution.
  • State bleed risk: Variables M and A are shared between the main program and the subroutine. If the subroutine were ever called without first resetting them (e.g. after an error), incorrect substrings could be extracted. However, RUN reinitialises all variables each cycle, so this is not an issue in practice.
  • REM at line 439 misspells “RANDOM” as “TANDOM” — a minor typo with no functional impact.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10294-10335.

Related Products

Related Articles

Related Content

Image Gallery

Random Sentences

Source Code

  10 LET M=1
  20 LET A=0
  30 SCROLL 
  40 RAND 0
  99 REM *SENTENCE SUBJECT*
 100 LET A$="DENNIS,GREG,SCOTTY,KENNY,HAL,DONALD,"
 110 LET E$=A$
 120 GOSUB 1000
 199 REM *VERB  OR PHRASE*
 200 LET B$="SPITS ALL OVER,HATES,KISSES,SITS ON,DROPS,"
 210 LET E$=B$
 220 GOSUB 1000
 299 REM *OBJECT OR PHRASE*
 300 LET C$="TOENAILS,DOG,COMPUTER,T.V.,PIZZA PAN,"
 310 PRINT "HIS "
 320 SCROLL 
 330 LET E$=C$
 340 GOSUB 1000
 399 REM *PREDICATE*
 400 LET D$="WHILE DRINKING BEER.,LIKE A MANIAC., AND ENJOYS IT.,BUT IS SORRY LATER.,WITH A VENGEANCE.,"
 410 LET E$=D$
 420 GOSUB 1000
 430 SCROLL 
 439 REM *RESEED TANDOM GENERATOR ROUTINE*
 440 IF INT (RND*100)<>5 THEN GOTO 440
 450 RUN 
 999 REM *RANDOM GENERATOR*
\n1000 RAND 
\n1010 FOR I=1 TO INT (RND*10)
\n1020 LET X=(RND*65535)
\n1030 NEXT I
\n1039 REM *PICK RANDOM DATA*
\n1040 LET X=INT (RND*5)+1
\n1050 FOR N=1 TO LEN E$
\n1060 IF E$(N)="," THEN GOTO 2000
\n1070 NEXT N
\n1080 RETURN 
\n1999 REM *FIND SEPARATOR*
\n2000 LET A=A+1
\n2010 IF A=X THEN GOTO 3000
\n2020 LET M=N+1
\n2030 GOTO 1070
\n2999 REM *FIND RANDOM DATA*
\n3000 PRINT E$(M TO N-1);" ";
\n3010 LET A=0
\n3020 LET M=1
\n3030 GOTO 1080
\n3040 CLEAR 
\n3050 SAVE "1029%5"
\n3060 RUN 

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

People

No people associated with this content.

Scroll to Top