We had a set of tickets to win at work today, and since i didn’t think it was fair that the first one to answer would win them, i rather had a raffle between the folks who responded to my mail within an hour.
But how do you draw a name from a hat in an impartial, elegant, fair and accountable way, rather than resorting to actual pen, paper and a hat? Enter Linux.
llauren@echkilon:~/tmp$ cat -> thehat
Alice
Bob
Carol
Dave
Eve
Isaac
Justin
Mallory
Oscar
Peggy
Steve
Trent
Walter
Zoe
llauren@echkilon:~/tmp$ shuf thehat | head -1
Eve
llauren@echkilon:~/tmp$ shuf thehat | head -1
Justin
llauren@echkilon:~/tmp$ shuf thehat | head -1
Walter
llauren@echkilon:~/tmp$
So there! The winner is Eve (scary!) with runners-up Justin and Walter. If we had three equal prices, the corresponding line would be shuf thehat | head -3.
I’m sure you could make the routine even more accountable by calculating a cryptographically valid hash of the result or at least signing the lottery session (since you can’t really store the evanescent value of /dev/urandom used for shuffling the hat), but i’ll leave that to a more critical use case.
Ah how i love Open source
