Posted to tcl by kostix at Mon Aug 25 22:44:18 GMT 2008view raw

  1. proc foo text {
  2. set words [regexp -all -indices -inline {[^[:punct:]\s]+} $text]
  3. set nwords [llength $words]
  4. array set seen {}
  5. set out $text
  6. for {set i 0} {$i <= int(rand() * $nwords)} {incr i} {
  7. while 1 {
  8. set ix [expr {int(rand() * $nwords)}]
  9. if {![info exists seen($ix)]} break
  10. }
  11. set seen($ix) yo!
  12. lassign [lindex $words $ix] a b
  13. set out [string replace $out $a $b [string repeat * [expr {$b - $a + 1}]]]
  14. }
  15. set out
  16. }

Comments

Posted by patthoyts at Mon Aug 25 23:15:11 GMT 2008 [text] [code]

testing

Posted by patthoyts at Wed Aug 27 13:40:45 GMT 2008 [text] [code]

another test