Add a shuffle utility

This commit is contained in:
Nick Chambers 2021-11-15 15:52:23 -06:00
parent a39c3ce06a
commit 4b2d6fcabb
1 changed files with 12 additions and 0 deletions

12
rowbot
View File

@ -97,6 +97,18 @@ any_file() {
fi
}
shuffle() {
local idx=0 spot tmp
declare -n rowbot_array=$1
for (( ; idx < ${#rowbot_array[@]}; idx += 1 )); do
spot=$(random 0 "${#rowbot_array[@]}")
tmp=${rowbot_array[$idx]}
rowbot_array[$idx]=${rowbot_array[$spot]}
rowbot_array[$spot]=$tmp
done
}
# misc
is_running () {