RosettaCodeData/Task/Pick-random-element/UNIX-Shell/pick-random-element.sh

13 lines
284 B
Bash

# borrowed from github.com/search?q=bashnative
rand() {
printf $(( $1 * RANDOM / 32767 ))
}
rand_element () {
local -a th=("$@")
unset th[0]
printf $'%s\n' "${th[$(($(rand "${#th[*]}")+1))]}"
}
echo "You feel like a $(rand_element pig donkey unicorn eagle) today"