Skip to content

Instantly share code, notes, and snippets.

@mriehl
Created May 22, 2013 08:19
Show Gist options
  • Save mriehl/5626039 to your computer and use it in GitHub Desktop.
Save mriehl/5626039 to your computer and use it in GitHub Desktop.
randomcowsay.sh Like cowsay (wrapper) but randomizes the animal. Randomization code is from http://rosettacode.org/wiki/Pick_random_element#Bash
#!/bin/bash
rand() {
printf $(( $1 * RANDOM / 32767 ))
}
rand_element () {
local -a th=("$@")
unset th[0]
printf $'%s\n' "${th[$(($(rand "${#th[*]}")+1))]}"
}
ANIMAL=$(rand_element `cowsay -l | grep -v files`)
cowsay -f $ANIMAL $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment