Requirements: to document a name randomly selected prize winners
Claim:
1, if no one hits the final round, the last round of the seeds from the selection again, rather than the entire set aside
2, winning staff can not be repeated
3, a complete lottery
Code:
lucky () { luckydog = (); # lucky stores winning lottery_list = $ ( the while Read Line; do echo $ Line { // / _}; DONE <filename); # read all the document names COUNT = $ ( echo " $ lottery_list " | WC - L); # Total Draw the number of echo -n " set the number of winning (can not exceed the total number of lottery COUNT $): " ; read num; the while ((NUM> COUNT)); do # NUM read from the screen to draw many people echo " The total number is " $ COUNT " people, the number of the winning set is greater than the total number of sweepstakes, please re-enter: " ; read num; done; for ((i=1; i <= $num; i++)) do # Num: winning screened by several people, Note: You may experience several rounds of screening hits, the last one hit talent is winning people echo " of the " $ i " lucky draw " ; seeds=$lottery_list; round=0; while (( round != 1 )); do last_namelist=$seeds; # Of people hit each round are stored in the variable seeds seeds=$(for line in $seeds;do ((RANDOM%2==1)) && echo $line;done); temp=$seeds; round = $ ( echo " $ Seeds " | WC - L); the current number of people hit the # IF [-n! " $ Seeds " ;] the then # If the current staff is hit empty, the last round hit man continue to draw until you hit a person seeds=$last_namelist; elif (($ round == 1 )); the then echo of the $ i Sweepstakes Winners: $ seeds; luckydog=("${luckydog[@]}" $seeds); # Deduplication: winning people to weed out the rest of the people continue to draw lottery_list = $ ( echo $ lottery_list | Sed " S / G $ // Seeds " ); the else Seeds = $ TEMP; # draw more than one of the wheel, continues to draw the assignment for Seeds Fi ; DONE ; DONE ; echo ; echo " All the people winning are: " $ {luckydog [@]} }