HomeRoast Digest


Topic: OT: "Pick Tradition Winner" script [Was: PCE 1.7-1.8k (48 lines)
1) From: Jeff Bensen
Aaron Peterson and I have exchanged several emails off-list regarding my 
attempt at an AWK script to randomly pick Tradition winners. Thanks to his 
excellent input, my script went from being unnecessarily complex to a thing 
of beauty. I am posting it here in case anyone else has an interest in 
using it for their Tradition.
If the script is saved under the name of "pick_winners.awk" and your list 
of names is called "names.txt", the script would be invoked as follows:
./pick_winners.awk names.txt
--------------------------------------------------
#!/usr/bin/gawk -f
# Input:  File with list of names, one per line
# Output: List of names in random order
{ list[++listCnt] = $0 }
END {
    srand()
     for (i=1; i<=listCnt; i++) {
       size = asort(list)
       pick = int( size * rand() ) + 1
       print  list[pick]
       delete list[pick]
    }
}
--------------------------------------------------
This script prints the entire list in random order, allowing you to select 
any number of winners by reading as many names from the beginning of the 
output as needed.
Aaron's original script (coded to choose two winners), written in Perl, 
appears below.
- Jeff Bensen
   Palm Bay, FL
At 07:28 PM 4/19/2006, "Aaron Peterson" wrote:
<Snip>


HomeRoast Digest