is a Western Christmas tradition in which members of a group or community are randomly assigned a person to whom they anonymously give a gift. Often practiced in workplaces or amongst large families, participation in it is usually voluntary. It offers a way for many people to give and receive a gift at low cost, since the alternative gift tradition is for each person to buy gifts for every other person. In this way, the Secret Santa tradition also encourages gift exchange groups whose members are not close enough to participate in the alternative tradition of giving presents to everyone else.
This software helps administer a Secret Santa exchange by performing three basic tasks:
- ASSIGN SECRET SANTAS: The program randomly pairs gifters with giftees and checks whether the user prohibited any of them (for example, the user might prohibit a husband getting his wife). If any assignment is prohibited, the program repeats until all the assignments are acceptable.
- EMAIL EACH PARTICIPANT HER ASSIGNMENT: This program uses R's mail package, which sends a maximum of 20 emails a day. See the mail documentation about disabling that limit.
- ESTIMATE THE PROBABILITY OF EACH SECRET SANTA PAIRING: The program uses simulation to estimate the probability of each pairing. This not only informs the user about participant X's chances of drawing participant Y; it also provides a check that the program correctly understood the user's pairing prohibitions (for example, spouses cannot draw each other.)
This program loads participant data (names; email addresses; and lists of prohibited assignees, such as spouses) from a user-created comma-separated file in the working directory with the name "secret santa participants.csv". The file should have the following structure:
- Participant names in the first column
- Participant email addresses in the second column
- The names of people the participant cannot get separated by a comma in the third column
- Variable names are "names", "email.addresses", and "prohibited".
Here is an example:
names | email.addresses | prohibited |
---|---|---|
Mike R. | [email protected] | |
Mike W. | [email protected] | Amy,John |
Amy | [email protected] | Mike W. |
John | [email protected] | Mike W. |
Emily | [email protected] |
Be sure to use unique names.
I wrote the code in R, a free and widely-used statistics-oriented programming language. There are several excellent references for R beginners:
- Code School's free, interactive tutorial in R
- R in a Nutshell
- A number of freely available "quick reference" sheets such as ones by Tom Short, and staff at the University of Auckland
This software relies on R's mail package. For more information on how to install this and other R packages, see here.