Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/python
import random
import base64
"""Secret Santa generator 0.1, trusted 1-party version.
Ever been dissatisfied with random santa assignment because the group would break up into smaller circles? This script prevents this.
Usage: Edit seed and names, run the script. Each participant will have the obfuscated name of the presentee printed next to their name, run it through the base64 decoder of your choice to reveal it.
There is no encryption, that means nothing is preventing you from spoilering yourself. Don't do it though.
Each combination of seed and names will give you exactly the same results each time you run the script, so test with a throwaway seed before generating the real list."""
seed = 1 # testing purposes
# seed = 20141224 # live seed, a date is good fit here
names = ['Donald', 'Daisy', 'Tick', 'Trick', 'Track']
"""generate random string from alphabet"""
def randomstring(l):
chars = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
return ''.join([random.choice(chars) for _ in range(l)])
"""pad string with random data"""
def obfuscate(s, l):
offset = random.randint(0, l - len(s))
return base64.b64encode(randomstring(offset) + s + randomstring(l - len(s) - offset))
generator = random.seed(seed) # reproducability
random.shuffle(names, generator) # random order while ensuring presence of exactly one circle
presents = zip(names, names[1:] + names[:1]) # copy, right rotate copy, zip
random.shuffle(presents, generator) # output list shouldn't betray present order
print 'seed: %s' % seed
print '\n'.join(['%s: %s' % (pair[0], obfuscate(pair[1], max(map(len,names)) + 5))
for pair
in presents])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment