Skip to content

Instantly share code, notes, and snippets.

@orirawlings
Created April 23, 2020 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orirawlings/bb66b0b5d99ebdf9fdbc305752fa5621 to your computer and use it in GitHub Desktop.
Save orirawlings/bb66b0b5d99ebdf9fdbc305752fa5621 to your computer and use it in GitHub Desktop.
Generate random backronyms using the dictionary at /usr/share/dict/words
BEGIN {
while((getline < "/usr/share/dict/words") > 0) {
first = substr($0, 1, 1)
wordcnts[first]++
words[first,wordcnts[first]] = $0
}
srand()
}
{
len = length($0)
for (i=1; i<=len; i++) {
l = substr($0, i, 1)
word = words[l,int(rand()*wordcnts[l])+1]
printf "%s%s", word, (i < len ? " " : "\n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment