Created
August 5, 2013 14:37
-
-
Save loisaidasam/6156385 to your computer and use it in GitHub Desktop.
Command line random word generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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