A late Christmas present

I wrote this because we wanted to do Secret Santa this year but Joe’s daughter’s live in California and wouldn’t be getting here until Dec 22nd. Joe used Bandcamp email voodoo to use the file generated to send the emails anonymously.

# Pair names for secret santa presents

import random as r
import sys

f = open('TestSanta.txt','w')

names = ["Joe","Alexa","Hannah","Xander","Kate","Soley","Max"]
secretsanta = ["Joe","Alexa","Hannah","Xander","Kate","Soley","Max"]

for name in names:
        x=r.randint(0,len(secretsanta)-1)
        receiver=secretsanta[x]
        while name is receiver:
                if len(secretsanta) == 1:
                        print "Run again"
                        sys.exit(0)
                else:
                        # If you get your own name put it back and pick again
                        # Want to go back to beginning of loop
                        x=r.randint(0,len(secretsanta)-1)
                        receiver=secretsanta[x]
        f.write(name +','+ receiver + '\n')
    del secretsanta[x]

f.close()

One thought on “A late Christmas present

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s