4 ms·
$ aspell dump master |sed -n $(echo $(($RANDOM % `aspell dump master|wc -l`)))p
by vikrum 15y ago
$ aspell dump master |sed -n $(echo $(($RANDOM % `aspell dump master|wc -l`)))p
- jannes 15y agoIs aspell a spellchecker? And does this command randomly select one word from its dictionary? (Note: I'm mostly a Windows user nowadays and I have never personally used aspell, sed, or wc) What does the p at the end of the line do? Is that a mistake or is it there on purpose?
- loumf 15y agoThe p prints the randomly chosen line -- wc -l is the number of lines in the file, (random % lines-in-file) picks a random one, 'sed -n 30p' prints the 30th line.
- pavel_lishin 15y agoAny advantage/disadvantage to replacing aspell dump master with cat /usr/share/dict/words ?
- felideon 15y agoToo bad zsh caches var expansion. :)
- Dobbs 15y agosh -c 'cat /usr/share/dict/words |sed -n $(echo $(($RANDOM % `cat /usr/share/dict/words |wc -l`)))p' I don't have aspell installed so 'cat /usr/share/dict/words' in place.
- braco_alva 15y agoThis is actually a good way to go or at least kind of fun for killing some time.
- captaincrowbar 15y agoProblem with this (and probably with the aspell version too, but I can't test that just now): $RANDOM only generates a number from 0 to 32767, but /usr/dict/words has (on my Mac) 235886 words.
- goblin89 15y agosh -c 'cat /usr/share/dict/words | sed -n $(echo $((`cat /dev/urandom | od -N3 -An -i` % `cat /usr/share/dict/words | wc -l`)))p' This is closer, although you might get sed: illegal option occasionally, I guess. I'm yet to learn how to generate a random number within given limits with bash. Oh wait, we can use Python can't we? sh -c 'cat /usr/share/dict/words | sed -n $(echo $((`python -c "import random; print random.randint(1,234935)"` % `cat /usr/share/dict/words | wc -l`)))p'
- ma2rten 15y agoMan, I got some really exotic words that way. Out of 10 words the only one I knew was bitripartite.