Secret Santa is a
traditional Christmas gift exchanging scheme in which each member of
a group is randomly and anonymously assigned another member to give
a Christmas gift to (usually by drawing names from a container). It
is not valid for a person to be assigned to themself (if someone
were to draw their own name, for example, all the names should be
returned to the jar and the drawing process restarted).
Given a group of a certain size, how many different ways are there
to make valid assignments? What is the probability that at least one
person will draw their own name? What is the probability that two
people will draw each other’s names? What is a good way to have a
computer make the assignments while guaranteeing they are generated
with equal probability among all possible assignments?
It turns out that these questions about secret santa present good
motivation for exploring some of the fundamental concepts in
combinatorics (the math of counting). In the sections below we will
take a look at a bit of that math and algorithms that allow us to
answer the questions we posed above. The final section presents a
simple command-line
program that allows
generating and anonymously sending secret santa assignments via
email so that we no longer need to go through the tedious ordeal of
drawing names from a hat.