#! /bin/bash # \ export TCL_LIBRARY=$HOME/tcl/lib/tcl ; \ exec /usr/local/bin/tclsh $0 "$@" array set Env \ [list \ {wlFile} {h:/TclStuff/wordhash.tcl} \ {minsize} 3 \ {maxsize} 15 \ {debug} 0 \ ] # Read the word list file. # puts -nonewline stderr {Reading word hash file...} flush stdout source $Env(wlFile) puts stderr {Done.} # Process the associative array for our purposes. # foreach {ix dat} [array get wordhash] { set len [string length $ix] # We only want to collect words of the correct length. # {Is this}/{are these}? # if {$len < $Env(minsize) || $len > $Env(maxsize)} \ continue # Yes, {it is}/{they are}. # eval lappend words($len) $dat } foreach {ix dat} [array get words] { set words($ix,len) [llength $words($ix)] } # Get rid of the original (humungous) array to conserve memory. # unset wordhash set len 6 while (1) { set wlist {} for {set n 4} {$n < 6} {incr n} { set wlist [concat $wlist $words($n)] } while {[set len [llength $wlist]]} { set ix [expr int( rand() * $len)] set thisword [lindex $wlist $ix] set wlist [lreplace $wlist $ix $ix] puts -nonewline "$thisword " flush stdout } } exit 0