Created
January 23, 2013 08:21
-
-
Save stevebest/4603082 to your computer and use it in GitHub Desktop.
Pick a random word from a dictionary
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
| #! /usr/bin/env bash | |
| WORDFILE="/usr/share/dict/words" | |
| words=$(wc -l $WORDFILE | grep -oP "\d+") | |
| r=$(((RANDOM * 32768 + RANDOM)%$words+1)) | |
| sed -n "$r p" $WORDFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
words=$(cat $WORDFILE | wc -l)works identically on Linux and Darwin and is a bit shorterhttps://gist.github.com/VSharapov/f4db3f2b8edc27bd8b9e3323e4869fcd#file-randword-sh-L4
Edit: but your version is more performant on Linux ... :
... and macOS: