Skip to content

Instantly share code, notes, and snippets.

@mpapi
Created January 29, 2013 03:38
Show Gist options
  • Save mpapi/4661609 to your computer and use it in GitHub Desktop.
Save mpapi/4661609 to your computer and use it in GitHub Desktop.
Generates a random password, after http://xkcd.com/936/.
#!/bin/bash
#
# Generates a random password, after http://xkcd.com/936/.
#
# -f [words file, one per line; default /usr/share/dict/words]
# -w [number of words; default 3]
# -n [min number of characters per word; default 6]
# -x [max number of characters per word; default 10]
#
set -u -e
WORDS=/usr/share/dict/words
NUM_WORDS=4
MIN_CHARS=6
MAX_CHARS=10
while getopts f:w:n:x: OPTION
do
case ${OPTION} in
f) WORDS=${OPTARG};;
w) NUM_WORDS=${OPTARG};;
n) MIN_CHARS=${OPTARG};;
x) MAX_CHARS=${OPTARG};;
esac
done
egrep "^[a-z]{${MIN_CHARS},${MAX_CHARS}}\$" ${WORDS} \
| shuf -n${NUM_WORDS} | xargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment