Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -r1.62 -r1.63 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 17 Dec 2003 19:21:22 -0000 1.62 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 18 Dec 2003 15:44:07 -0000 1.63 @@ -4697,3 +4697,17 @@ return $result } +ad_proc -public util::randomize_list { + list +} { + Returns a random permutation of the list. +} { + set len [llength $list] + set result [list] + while { [llength $list] > 0 } { + set index [randomRange [llength $list]] + lappend result [lindex $list $index] + set list [lreplace $list $index $index] + } + return $result +} Index: openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl,v diff -u -r1.18 -r1.19 --- openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl 6 Dec 2003 15:11:16 -0000 1.18 +++ openacs-4/packages/acs-tcl/tcl/test/acs-tcl-test-procs.tcl 18 Dec 2003 15:44:07 -0000 1.19 @@ -718,3 +718,24 @@ } +aa_register_case util__randomize_list { + Test util::randomize_list +} { + aa_equals "Emtpy list" [util::randomize_list {}] {} + + aa_equals "One-element list" [util::randomize_list {a}] {a} + + aa_true "Two-element list" [util_sets_equal_p [list a b] [util::randomize_list [list a b]]] + + set org_list [list a b c d e f g h i j] + set randomized_list [util::randomize_list $org_list] + aa_true "Ten-element list: $randomized_list" [util_sets_equal_p $org_list $randomized_list] + + set len [randomRange 200] + set org_list [list] + for { set i 0 } { $i < $len } { incr i } { + lappend org_list [ad_generate_random_string] + } + set randomized_list [util::randomize_list $org_list] + aa_true "Long random list" [util_sets_equal_p $org_list $randomized_list] +}