From 967ad3643c540d3b40f64cc51b4aff6340662ffb Mon Sep 17 00:00:00 2001 From: antirez <antirez@gmail.com> Date: Fri, 13 Jul 2018 17:51:03 +0200 Subject: [PATCH] Test: add lshuffle in the Tcl utility functions set. --- tests/support/util.tcl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/support/util.tcl b/tests/support/util.tcl index 64c36b32..b3c3abca 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -375,3 +375,17 @@ proc start_write_load {host port seconds} { proc stop_write_load {handle} { catch {exec /bin/kill -9 $handle} } + +# Shuffle a list. From Tcl wiki. Originally from Steve Cohen that improved +# other versions. Code should be under public domain. +proc lshuffle {list} { + set n [llength $list] + while {$n>0} { + set j [expr {int(rand()*$n)}] + lappend slist [lindex $list $j] + incr n -1 + set temp [lindex $list $n] + set list [lreplace [K $list [set list {}]] $j $j $temp] + } + return $slist +}