set display mode 800,600,32
sync on : sync rate 0 : sync : sync
set text font "verdana" : set text size 16
seed = timer() : randomize seed
#constant vowelMax = 15
data "a","a","a","a","e","e","e","e","i","o","o","o","u","ea","ie","ee"
#constant consonantMax = 28
data "b","c","d","f","g","h","j","k","l","m","m","m","m","n","n","n","n","p","r","s","t","t","t","t","w","ph","th","tr","br"
#constant softMax = 6
data "h","r","m","m","m","m","s"
#constant lastMax = 2
data "d","m","n"
dim vowel(vowelMax) as string
dim consonant(consonantMax) as string
dim soft(softMax) as string
dim last(lastMax) as string
for datIndex = 0 to vowelMax : read vowel(datIndex) : next datIndex
for datIndex = 0 to consonantMax : read consonant(datIndex) :next datIndex
for datIndex = 0 to softMax : read soft(datIndex) : next datIndex
for datIndex = 0 to lastMax : read last(datIndex) : next datIndex
 
if file exist("tomuNames.txt") then delete file "tomuNames.txt"
open to write 1,"tomuNames.txt"
   repeat
      ink rgb(255,0,0),0 : print "Random Seed: ",seed
      for nameNum = 1 to 30
         for col = 1 to 3
            ink rgb(0,128,255),0
            name$ = makeName(2 + rnd(1)) : lastName$ = makeName(2 + rnd(1))
            if name$ = "tomu" || name$ = "tom" then ink rgb(255,128,0),0
            center text 200 * col , 50 + nameNum * 15 , upper$(left$(name$,1)) + right$(name$,len(name$)-1) + " " +  upper$(left$(lastName$,1)) + right$(lastName$,len(lastName$)-1)
            write string 1 , upper$(left$(name$,1)) + right$(name$,len(name$)-1) + " " +  upper$(left$(lastName$,1)) + right$(lastName$,len(lastName$)-1)
         next col
      next nameNum
      ink rgb(255,255,255),0 : center text 400 , 50 + ( 1 + nameNum ) * 15 , "press "q" to quit. other entry to continue generating"
      set cursor 200 , 50 + ( 3 + nameNum ) * 15 : input answer$
      sync
      cls
   until answer$ = "q"
close file 1
function makeName( syllables )
   for sylN = 1 to syllables
      repeat
         if lastLength > 0
            if lastLetter = 1
               length = 2 + rnd(1)
               if length = 2
                  choice = 1
               else
                  choice = rnd(1)
               endif
            else
               length = 2 + rnd(1)
               choice = 0
            endif
            if length = 2
               if rnd(1) = 1 && lastLetter = 1
                  length = 3
                  choice = 1
               endif
            endif
            if sylN = syllables
               if rnd(0) = 0
                  if lastLetter = 1
                     length = 1
                     choice = 1
                  else
                     length = 1
                     choice = 0
                  endif
               endif
            endif
         else
            length = 2 + rnd(1)
            choice = rnd(1)
         endif
      until length <> lastLength || (sylN = syllables && length = 1)
      lastLength = length
      repeat
         vowelA$ = vowel( rnd(vowelMax) ) : vowelB$ = vowel( rnd(vowelMax) )
         consonant$ = consonant( rnd(consonantMax) )
         soft$ = soft( rnd(softMax) )
         harsh$ = consonant( rnd(consonantMax) )
         last$ = last( rnd(lastMax) )
         same = (consonant$ = soft$) || ( sylN < syllables && vowelA$ = "ie" ) || (sylN < syllables && soft$ = "s") || (lastVowel$ = vowelA$) || (len(harsh$) < 2) || ((sylN = 1 && length = 2) && (choice = 0 && len(vowelA$) > 1))
         same = same || (len(consonant$) > 1) || (len(lastVowel$) = 2 && len(vowelA$) = 2) || (right$(harsh$,1) = vowelA$) || (len(vowelA$) = 2 && len(vowelB$) = 2) || (sylN = syllables && consonant$ = "j")
         same = same || (lastConsonant$ = "f" && consonant$ = "ph") || (lastConsonant$ = "ph" && consonant$ = "f")
      until same = 0
      lastVowelA$ = vowelA$
      lastConsonant$ = consonant$
      select length
         case 1
            if choice = 1
               syllable$ = last$
            else
               syllable$ = vowelA$
            endif
         endcase
         case 2
            if choice = 1
               syllable$ = consonant$ + vowelA$
            else
               syllable$ = vowelA$ + consonant$
            endif
         endcase
         case 3
            if choice = 1
               syllable$ = consonant$ + vowelA$ + soft$
            else
               syllable$ = harsh$ + vowelA$
            endif
         endcase
      endselect
      name$ = name$ + syllable$
      lastLetter$ = right$(name$,1) : lastLetter = lastLetter$ = "a" || lastLetter$ = "e" || lastLetter$ = "i" || lastLetter$ = "o" || lastLetter$ = "u"
   next sylN
endfunction name$