Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Created January 28, 2020 23:46
Show Gist options
  • Save SmugZombie/4d759877754c45fc4d79e94939f04f66 to your computer and use it in GitHub Desktop.
Save SmugZombie/4d759877754c45fc4d79e94939f04f66 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Randomword.sh
# Ron Egli - github.com/smugzombie
WORDFILE=/usr/share/dict/words
WORD=
VALID=0
function randomword {
RANDOM=$(date +%s%N);
# echo $RANDOM
# using cat means wc outputs only a number, not number followed by filename
lines=$(cat $WORDFILE | wc -l);
rnum=$((RANDOM*RANDOM%$lines+1));
WORD=$(sed -n "$rnum p" $WORDFILE);
}
function checkword {
# echo "Running Checkword: $WORD"
# Some entries may have 's, we dont want them in our output so invalidate and move on.
if [[ $WORD == *"'"* ]]; then
VALID=0
# echo "INVALID"
else
VALID=1
# echo "VALID"
fi
}
randomword checkword while [ $VALID -eq 0 ]; do
randomword
checkword
done
echo $WORD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment