Skip to content

Instantly share code, notes, and snippets.

@loisaidasam
Created August 5, 2013 14:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loisaidasam/6156385 to your computer and use it in GitHub Desktop.
Save loisaidasam/6156385 to your computer and use it in GitHub Desktop.
Command line random word generator
#!/bin/bash
DICT="/usr/share/dict/words"
NUM_WORDS=$(wc -l $DICT | awk -F " " '{print $1}')
NUM_DIGITS=${#NUM_WORDS}
while true
do
NUM=""
for ((i=0; i<$NUM_DIGITS; i++))
do
DIGIT=$(($RANDOM%10))
NUM="$NUM$DIGIT"
done
if [ $NUM -le $NUM_WORDS ]
then
break
fi
done
WORD=$(head -n $NUM $DICT |tail -n 1)
echo $WORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment