Index: openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl,v diff -u -r1.57.2.10 -r1.57.2.11 --- openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl 22 Nov 2019 16:15:25 -0000 1.57.2.10 +++ openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl 25 Jan 2020 13:40:39 -0000 1.57.2.11 @@ -54,6 +54,35 @@ return $text } + ad_proc randomized_indices {-seed length} { + # + # Produce a list of "length" random numbers between 0 and + # length-1. + # + } { + # In case, the seed is specified, set the seed to this value to + # achieve e.g. a stable bat random order for a user. + # + if {[info exists seed]} { + expr {srand($seed)} + } + # + # Produce shuffled indices between 0 and length-1. + # + set indices {} + for {set i 0} {$i < $length} {incr i} { + lappend indices $i + } + set shuffled {} + incr length + for {} {$length > 1} {incr length -1} { + set i [expr {int(($length-1) * rand())}] + lappend shuffled [lindex $indices $i] + set indices [lreplace $indices $i $i] + } + return $shuffled + } + # # # Helper for virus checks