one can sort a list using the lsort command, is there a way to randomize the list... or a method of using the lsort -command option to randomize it??
thanks
Code: Select all
proc randlist { list } {
# determine length of list
set listlength [llength $list]
# iterate on list, decrease length per iteration
for { set i $listlength } { $i > 1 } { incr i -1 } {
# choose random index
set randindex [rand $i]
# pick the random item
set randitem [lindex $list $randindex]
# cut the random item from the list
set list [lreplace $list $randindex $randindex]
# paste the random item at the end of the list
set list [lappend list $randitem]
}
return $list
}
Code: Select all
bind dcc - randlist makerandlist
proc makerandlist { handle idx arg } {
set list "1 2 3 4 5 6 7 8 9 10"
putlog [randlist $list]
}