Hacker News new | ask | show | jobs
by felideon 5412 days ago
Too bad zsh caches var expansion. :)
1 comments

    sh -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.
This is actually a good way to go or at least kind of fun for killing some time.
Problem 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.

    sh -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'