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 -N -r1.57.2.19 -r1.57.2.20 --- openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl 25 Feb 2021 10:01:36 -0000 1.57.2.19 +++ openacs-4/packages/xowiki/tcl/xowiki-utility-procs.tcl 15 Mar 2021 22:22:18 -0000 1.57.2.20 @@ -55,17 +55,17 @@ } ad_proc randomized_indices {-seed length} { - # - # Produce a list of "length" random numbers between 0 and - # length-1. - # - # Measure quality of randomization: - # - # time {lappend _ [xowiki::randomized_indices -seed [clock microseconds] 3]} 1000 - # foreach t $_ { - # lassign $t a b c; dict incr stats "a $a"; dict incr stats "b $b"; dict incr stats "c $c" - # } - # set stats + Produce a list of "length" random numbers between 0 and + length-1. + + Measure quality of randomization: +
+      time {lappend _ [xowiki::randomized_indices -seed [clock microseconds] 3]} 1000
+      foreach t $_ {
+        lassign $t a b c; dict incr stats "a $a"; dict incr stats "b $b"; dict incr stats "c $c"
+      }
+      set stats
+    
} { # In case, the seed is specified, set the seed to this value to # achieve e.g. a stable bat random order for a user. @@ -92,6 +92,20 @@ return $shuffled } + + ad_proc randomized_index {-seed length} { + Produce a single randomized index 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)} + } + return [expr {int(($length-1) * rand())}] + } + # # # Helper for virus checks