applets.

Secret Santa

← All apps

About Secret Santa

Everyone's name goes into a hat, everyone draws one out, and buys a present for whoever they drew, without saying. The snag is drawing your own name. This page shows how often that happens, what people do about it, which of those fixes are fair, and makes a fair draw for you.

THE HAT: type the names (or keep the sample) and press DRAW (or D, or click the hat). The slips come out one at a time and land on each person's card. With REDRAW, as soon as someone opens their own name every slip goes back and you start again; CARRY ON keeps whatever comes out, so you can see how often someone gets themselves. Put a couple or a household on one line with & (Anna & Ben) and tick own household too to redraw when someone gets their partner as well. The card on the right shows the loops the draw made and the odds for your group.

THE MATHS: the odds for 2 to 20 people, and a simulation: pick the group size and how many draws, then RUN (or R).

IS IT FAIR?: four ways people run the hat, each simulated many times for 3, 4 or 5 people. Every possible result gets a bar; a fair method gives them all the same height (the dashed line). The grid shows who ended up buying for whom.

SECRET DRAW: a real draw for your group. MAKE THE DRAW, then pass the screen round: each person clicks their own envelope, presses SHOW ME, reads their name and presses HIDE IT. Nobody, the organiser included, sees the whole list. The names and the draw are kept on this computer only (so closing the page doesn't lose them) and never go into a link; FORGET wipes them.

THE STORY

Giving presents in secret is an old custom in many places. In Scandinavia a julklapp was a Christmas present knocked on the door and thrown in by a giver who didn't stay to be seen; in German-speaking countries the name-drawing game is Wichteln, after the helpful little elves of folk tales. In English it is Secret Santa, a fixture of offices and families.

The maths is older than the party game. In 1708 Pierre Rémond de Montmort, in his book on games of chance, asked about a card game called Treize (thirteen): deal the cards out while counting one to thirteen, and what is the chance that some card turns up on its own number? He and Nicolaus Bernoulli worked it out in the years that followed, and Leonhard Euler came back to it later. It is called the problème des rencontres, the problem of matches, and is the same question as a hat with nobody drawing themselves, or a cloakroom handing hats back at random. The arrangements where nothing lands on its own place are called derangements, and their number is written !n.

The loops a draw makes are the key to another famous puzzle: 100 prisoners, 100 drawers, and a plan that works almost a third of the time. See 100 Prisoners on this site.

Counting draws that avoid couples is a cousin of the problème des ménages (seating couples round a table, men and women alternating, nobody next to their partner), and the tool used here, the rook polynomial, comes from Irving Kaplansky and John Riordan's 1946 paper on it.

HOW IT WORKS

How many draws work. n people can draw the n slips in n! orders. Count the ones where nobody draws themselves by inclusion and exclusion: all n!, take away the ones where a chosen person has their own slip, add back those where two chosen people do, and so on. That gives !n = n! (1 − 1/1! + 1/2! − 1/3! + … ± 1/n!), or the shortcut !n = (n − 1)(!(n − 1) + !(n − 2)). The bracket is the start of the series for 1/e, so the chance that a draw works settles at 1/e = 36.79% (to two decimal places) for any group of seven or more: nearly two draws in three need redoing, however many people there are. The number of draws until one works is a geometric wait, averaging n!/!n ≈ e ≈ 2.72.

Exactly one person, on average. Each of n people has a 1 in n chance of their own slip, so on average exactly 1 person draws themselves, for any n. The number who do is close to a Poisson spread: none 36.8%, one 36.8%, two 18.4%, three 6.1%.

Which fixes are fair. Putting every slip back and redrawing whenever anyone has themselves is fair: every first draw is equally likely, and you keep the first one that's allowed, so every allowed result is equally likely too. Swap with your neighbour (whoever has themselves swaps slips with the next person round) is not: it can only ever push a slip one place along, so some results come from many first draws and others from only one. Draw in turn, put yourself back isn't either: whoever draws first chooses from more slips than the people after, and the last person sometimes finds only their own slip left. The page works out each method's exact odds by following every possible first draw (or every path through the turns), and checks them by simulation. One big loop (shuffle the names round a circle, everyone buys for the next) is fair to each person, who is equally likely to get any of the others, but only ever makes one loop: of the !n allowed results it only makes the (n − 1)! single loops, a share of about e/n (34% of them for 8 people).

Households. Mark the forbidden squares in the giver-by-receiver grid: one full block for each household (the diagonal is everyone's own household of one). The number of ways to put k non-attacking rooks on a block of m is C(m, k)² × k!, and blocks don't share rows or columns, so their rook polynomials multiply. Then the allowed draws are Σ (−1)k rk (n − k)!. The tests check it against trying every arrangement.

The secret draw uses your browser's cryptographic random numbers. It shuffles, and if anyone has someone from their own household it shuffles again: the hat with redraws, done in a blink, so every allowed draw is equally likely. With one big loop it shuffles the names round a circle instead, again until nobody's next to their own household. Nothing is sent anywhere.

FURTHER WATCHING AND READING

Who's in the hat?

One per line or with commas. A couple or household on one line with & (Anna & Ben) is kept apart in the secret draw, and in the hat with own household too.

Kept on this computer only, never in a link.

If someone draws themselves

What happened

    The loops

    Odds for this group