Skip to content

Instantly share code, notes, and snippets.

@claylo
Created September 7, 2012 15:51
Show Gist options
  • Save claylo/3667348 to your computer and use it in GitHub Desktop.
Save claylo/3667348 to your computer and use it in GitHub Desktop.
Are we there yet?
#!/bin/bash
# The author releases this code into the public domain.
# requires 'say' command. OS X is your friend
RANGE=90
LOOPS=10
count=0
# Thanks, interwebs!
# http://rosettacode.org/wiki/Pick_random_element#Bash
rand() {
printf $(( $1 * RANDOM / 32767 ))
}
rand_element() {
local -a th=("$@")
unset th[0]
printf $'%s\n' "${th[$(($(rand "${#th[*]}")+1))]}"
}
# loop for a while
echo "looping $LOOPS times"
while [ "$count" -le $LOOPS ]
do
number=$RANDOM
let "number %= $RANGE"
let "count += 1"
the_voice=$(rand_element \
Agnes \
Albert \
Alex \
"Bad News" \
Bahh \
Bells \
Boing \
Bruce \
Bubbles \
Cellos \
Deranged \
Fred \
"Good News" \
Hysterical \
Junior \
Kathy \
"Pipe Organ" \
Princess \
Ralph \
Trinoids \
Vicki \
Victoria \
Whisper \
Zarvox)
say "are we there yet?" --voice "$the_voice"
echo "...asked $the_voice (loop $count, sleeping $number)"
sleep $number
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment