randomize timer()
 
data "e","e","e","e","u","i","i","o","o","a","a","a"
data "q","w","r","r","r","t","t","t","t","y","p","p","s","s","s","s","d","d","f","f","g","g","h","j","k","l","l","l","z","x","c","c","v","b","b","n","n","n","m","m","m"
data "dale","vale","ton","by","town","ville","land","ly","ford","gate","chester"
 
`read vowels
dim vowel$(12)
for n=1 to 12
read vowel$(n)
next n
 
`read consonants
dim consonant$(41)
for n=1 to 41
read consonant$(n)
next n
 
`read endings
dim ending$(11)
for n=1 to 11
read ending$(n)
next n
 
numberofwords=10
dim word$(numberofwords)
 
do
 
for repeatword=1 to numberofwords
 
  `start word with a consonant
  consonant=1
  vowel=-1
 
  `randomize word length
  numberofletters=3+rnd(7)
  dim letter$(numberofletters)
 
  for repeatletter=1 to numberofletters
 
    `select random consonant
    if consonant=1
      letter$(repeatletter)=consonant$(rnd(40)+1)
    endif
 
    `select random consonant
    if vowel=1
      letter$(repeatletter)=vowel$(rnd(11)+1)
    endif
 
`****RULES AND EXCLUSIONS****
 
`prevent word starting with certain letters
if letter$(repeatletter)="x" and repeatletter=1 then dec repeatletter:goto endofloop
`prevent word ending with certain letters
if letter$(repeatletter)="x" or letter$(repeatletter)="j" or letter$(repeatletter)="z" or letter$(repeatletter)="g" or letter$(repeatletter)="u" or letter$(repeatletter)="k" or letter$(repeatletter)="h" and repeatletter=numberofletters then dec repeatletter:goto endofloop
 
`prevent word ending in q, or penultimate letter being q
if letter$(repeatletter)="q" and repeatletter>numberofletters-2 then dec repeatletter:goto endofloop
 
`if previous letter is q, make next letter u, and force a second vowel
if letter$(repeatletter-1)="q" then letter$(repeatletter)="u":goto endofloop
`prevent two u's in a row after a q
if letter$(repeatletter-1)="u" and letter$(repeatletter)="u" then dec repeatletter:goto endofloop
 
if repeatletter=1 then letter$(repeatletter)=upper$(letter$(repeatletter))
`****************************
 
`allow two syllable six letter words
if numberofletters=6 and repeatletter=3
`do nothing`
else
`alternate between consonant and vowel
consonant=consonant*-1
vowel=vowel*-1
endif
 
endofloop:
 
  next repeatletter
 
  `build the word from the chosen letters
  word$(repeatword)=""
  for buildword=1 to numberofletters
    word$(repeatword)=word$(repeatword)+letter$(buildword)
  next buildword
 
  `add word endings
  if letter$(numberofletters)="c" then word$(repeatword)=word$(repeatword)+"k"
  if letter$(numberofletters)="v" then word$(repeatword)=word$(repeatword)+"e"
  if numberofletters<8
    end$=ending$(rnd(10)+1)
    word$(repeatword)=word$(repeatword)+end$
endif
 
 
 
  print word$(repeatword)
 
next repeatword
 
 
print
print "Press space to regenerate"
print "Press 's' to save to file"
 
repeat
 
`save words to file
if inkey$()="s"
  if file exist ("c:wordgenerator.txt") then delete file "c:wordgenerator.txt"
  open to write 1,"c:wordgenerator.txt"
  for repeatword=1 to numberofwords
    write string 1,word$(repeatword)
  next repeatword
  print "Saved as 'c:wordgenerator.txt'"
  close file 1
  wait 1000
endif
 
 
until spacekey()=1
wait 200
cls
loop