How to choose ?
Par jd le jeudi, mars 3 2005, 14:57 - Life - Lien permanent
How to choose when you don't know ? Ask zsh !
% S=(work cleanupmyflat) ; echo ${S[$(($RANDOM % ${#S[*]} + 1))]}
cleanupmyflat
Oh my god...
Update: for bash users:
% S=(work cleanupmyflat) ; echo ${S[$(($RANDOM % ${#S[*]}))]}
Commentaires
But the "+1" at the end makes it display either "cleanupmyflat" or nothing. Without the "+1" it seems to work. Or was that an intended behavior?
Nico.
No, at least with my zsh it works: $RANDOM % 2 return 0 or 1 but array index begins at 1 so you have to add 1
python -c 'import random ; s=("work", "cleanupmyflat") ; print random.choice(s)'
And for both (bash and zsh) :
S=(work cleanupmyflat work) ; echo ${S[$(($RANDOM % $((${#S[*]} - 1)) + 1))]}
;D
... cat /dev/urandom > /dev/dsp
and if still unsure, you can organise a poll:
S=(work cleanupmyflat) ; for i in `seq 1000`; do echo ${S[$(($RANDOM % ${#S[*]}))]}; done | sort | uniq -c | sort -rn
It didn't give the result I wanted, so here is a (bash) patch:
S=(work cleanupmyflat) ; echo ${S$(($RANDOM % ${#S[*}))]}"? nah, I don't think so"
Fil des commentaires de ce billet