Simple Random Number Generator For #codemash

Each #CodeMash attendee's badge had a unique integer that was used in a raffle to give away prizes. Unfortunately random.org was used to pick the set of lucky winners. Unsurprisingly the sequences of random numbers generated by random.org contained duplicates. Several numbers like 123 were called 3 or 4 times. I would have liked each number to be called only once. Python to the rescue. To get a randomized list of all attendees:
import random, sys
all_attendees = range(550)
random.shuffle(all_attendees)
When run this script will print a random number each time you press enter until the range is exhausted. CTRL-D will let you exit early if all the prizes are gone. The range is 0-549.
import os
import random
all_attendees = range(550)
random.shuffle(all_attendees)
for attendee in all_attendees:
    try:
        raw_input()
    except EOFError:
        os.exit(0)
    print attendee
print '\\nAll attendee numbers have been exhausted.'
Replace 550 with the actual number of attendees.
blog comments powered by Disqus