Do make sure certain chores get no prevalence over other chores, association-wise, I made a little worklist randomizer.
Lets say I have a number of chores in a list:
set w { {washing up} {cut the grass} {shave (very important!)} {watch CNN} {finish some Tcl programs} {work in computer field} {buy tickets in a lottery} {go voting (even more important!)} {etc (whatever else comes up)} }
Now we want a random iten from the list, or a random permutation of the list, with no priorities:
lindex $w [expr int(9*rand())]
Of course we could do the same with the rest of the list.
Googie 17.09.2008 - I'd upgrade method of retrieving random entry:
lindex $w [expr { int([llength $w]*rand()) }]
But there is still missing solution for removing from list jobs that are already done. So we need a procedure for that:
proc lremove {varName idx} { upvar $varName lst set val [lindex $lst $idx] set lst [lreplace $lst $idx $idx] return $val }
and finally:
lremove w [expr { int([llength $w]*rand()) }]
TV I had made this:
proc randout l { set i [expr int([llength $l]*rand())] ; return [list [lindex $l $i] [lrange $l 0 [expr $i-1] ] [lrange $l [expr $i+1] end ]] }
This is a list shuffler which can be made recursive, but it escaped me how to make a flat combined list...
( Example: (Tcl) 62 % randout $w
{go voting (even more important!)} {{washing up} {cut the grass} {shave (very important!)} {watch CNN} {finish some Tcl programs} {work in computer field} {buy tickets in a lottery}} {{etc (whatever else comes up)}}
)
Of course I know how to do that:
proc randout l { set i [expr int([llength $l]*rand())] ; return "[lindex $l $i] [lrange $l 0 [expr $i-1] ] [lrange $l [expr $i+1] end]" }
enter categories here |
---|