Three people put their names in a hat for Secret Santa. Each takes a slip in turn; if you draw your own name you put it back and draw again, and if the last person is left holding only their own slip, everyone starts over. There are exactly two possible outcomes, two circles going opposite ways. Most people would say each comes up half the time.
Follow the branches. Call the drawers A, B and C, in that order. A can't keep their own slip, so A gets B or C, a half each.
- If A drew C, the hat holds A and B. B can't take their own name, so B takes A, and C gets B. That is the circle A→C→B→A, with weight ½.
- If A drew B, the hat holds A and C. Half the time B takes C and C gets A: the circle A→B→C→A, weight ¼. The other half, B takes A, C is left with their own slip, and everyone starts over.
After the restarts, the two circles come out 2/3 and 1/3. The hat is not fair even at three.
The bias has a clean law
With n people and no other rules, the hat's likeliest draw is exactly n − 1 times as likely as its least likely. The proof fits in a paragraph. A draw's chance is a product with one factor per person: 1 over the number of slips that person may take when their turn comes. The first person always has n − 1 choices and the last always has one. Everyone else, person k counting from 0, has either n − k − 1 choices (their own slip is still in the hat) or n − k (someone already drew it). The draw where everyone gives to the person before them, and the first to the last, keeps every own slip in the hat until its owner's turn; the draw where everyone gives to the person after them removes each one first. The ratio of the two products telescopes:
(n−1)/(n−2) × (n−2)/(n−3) × … × 2/1 = n − 1 We computed every case from 3 to 9 people exactly, with BigInt fractions and no simulation, and the table agrees. That the hat is lopsided is not new. Jerrold Grossman's OEIS sequence A102262 (2005) and Brian Parsonnet's A136300 (2008) give how often the last person gets stuck; Parsonnet's notes (2011) count each drawer's choices exactly the way the product above needs, and Pranav Hosamani's 2026 essay writes the product out; the Possibly Wrong blog showed in 2010 that the results are nowhere near uniform even with restarts. Our code reproduces the published figures (stuck probabilities 1/4, 5/36 and 19/144 for three, four and five people; the blog's ratio of 1.94869 at nine). The n − 1 ratio follows from that product in a line, but we did not find it stated anywhere.
Drawing fairly is the easy part
"Fair" here means every draw that follows your rules has the same chance. The simplest exact method is the one people half-remember: shuffle everyone, and if anyone breaks a rule, shuffle again. Every shuffle is equally likely and every valid draw comes from exactly one shuffle, so the kept one is uniform. (Use a cryptographic source and draw integers without modulo bias.)
It is slow only when valid draws are a tiny fraction of all shuffles, for example an office of forty that wants every pair to cross between two teams of twenty. For that case we used Mark Huber and Jenny Law's 2008 sampler, which builds a draw recipient by recipient and throws the attempt away with whatever probability is left over, using an upper bound on the permanent. It is exact, and it is easy to get backwards: the inequality runs down a column (one recipient, every possible giver) with the bound on row sums. Expand along a row instead and, for a family of five with two couples, the weights for the single person's draw add up to 1.0099. That version would quietly favour some draws. Our sampler throws an error if its weights ever exceed 1, and the verifier checks the sum at every step, and checks that the wrong orientation does exceed 1.
How do you know a uniformity test can fail? Run the hat through it. On the same family, at the same sample size, the samplers pass a chi-square test against equal counts, and the hat fails it by a wide margin.
When no draw exists, say why
With enough couples and exclusions there may be no valid draw at all. Philip Hall's theorem (1935) says a draw exists exactly when every group of k people may, between them, draw at least k different names. So when there is none, there is a group that can't, and you can find it from a failed matching: follow alternating paths from a giver left without a name, and the people you reach may draw one name fewer than there are of them. We then shrink the group until nobody can be removed, and print it with each member's allowed names. For a household of four with only two other people:
Ann, Ben and Cat are 3 people, but between them they may only draw Eve or Fay: 2 names for 3 people. You can check that with a pencil.
What the rules give away
This was the part we did not find in any of the generators we checked. Exclusions can leak the secret on their own: if the rules leave someone one possible name, anyone who knows the rules knows who has whom. With three people and no other rules, your slip tells you exactly who has you, every time. With two couples and "no two-person swaps" switched on, only two draws are left and everyone can work it out. So the page counts the draws exactly for small groups (a subset dynamic program: the count is the permanent of the who-may-draw-whom matrix), shows every pairing's exact chance before anyone draws, finds forced pairings with a little matching theory, and says how often a person could name their own Santa from their slip.
Keeping the list private, and the side channel we nearly shipped
Each person gets a link with their pairing after the #, which browsers never send to a server. The first script on the page copies that part into memory and wipes it from the address bar before any other script runs, and a Content-Security-Policy stops the page contacting any other website. The organiser's screen shows only the givers' names.
One leak we found by asking a reviewer to attack the page as a nosy organiser: a link's length grew with the recipient's name, so comparing the links of one draw hinted at who had whom. Our first fix padded every link to the longest slip in the draw, and the reviewer showed that still leaked, because the longest slip depends on who drew whom (with one long gift hint, the length named one person's Santa every time). Links are now padded to a length fixed by the names, details and hints alone.
We are not the first careful generator. Toggle9's (by Jeremiah Say) already draws in the browser with links after the # and explains impossible draws with Hall's theorem; AgentCalc's counts valid draws exactly for up to 18 people; MiniWebtool's and VISU's keep the result off the organiser's screen. What this one adds is the account of what the rules give away, uniform draws at every size with no unequal fallback, last year's draw avoided from a saved file without being shown, and printable QR slips.
The tool is Secret Santa, drawn privately, and the measurements and checks are on Is Secret Santa fair?.

