3 ms·
If you're on linux you can usually just do: shuf -n 5 /usr/share/dict/words On Mac OS X you need coreutils for shuf, which you can get from brew (it's cal
by __david__ 12y ago
If you're on linux you can usually just do:
shuf -n 5 /usr/share/dict/words
On Mac OS X you need coreutils for shuf, which you can get from brew (it's called gshuf once installed).
- anonfunction 12y agoTo get rid of the newlines shuf -n 4 /usr/share/dict/words | xargs | sed 's/ //g'
- __david__ 12y agoOr slightly more simply: echo `shuf -n 5 /usr/share/dict/words`
- sarciszewski 12y agoMaybe add this to your .bashrc file? randword() { if [ -z $1 ]; then echo `shuf --random-source=/dev/urandom -n 5 /usr/share/dict/words` else echo `shuf --random-source=/dev/urandom -n $1 /usr/share/dict/words` fi } Test output: kobra@stormforge blah $ randword 4 crackpots fragmentation maximally Bradly's kobra@stormforge blah $ randword 6 turnover's nonproliferation's bestowal's sulkier hillbilly Narmada kobra@stormforge blah $ randword Marciano fibulas roadwork mobilizations organics kobra@stormforge blah $ randword coins bronzed housemother's forefather supposing
- eric_bullington 12y agoI would be very cautious about using shuf for password generation, since it doesn't use a cryptographically-secure random number generator (I just checked the source). Edit: I see that shuf permits the use of custom seeds, so you can do the following, and it will be secure: shuf -n 5 --random-source=/dev/urandom /usr/share/dict/words
- _paulc 12y agoOr: python -c 'import random;w=open("/usr/share/dict/words").readlines();print " ".join([random.choice(w).strip() for _ in range(5)])'