How does this Secret Santa generator pick who buys for whom?
This Secret Santa generator shuffles your list with your browser's secure random source, then checks the result against your rules: nobody draws their own name, and no excluded pair draws each other. If a shuffle breaks a rule it is thrown away and the page shuffles again. A draw that passes has a name in mathematics, a derangement: a reordering in which no item stays in its original place.
The shuffle is a Fisher–Yates shuffle driven by crypto.getRandomValues(), with rejection sampling so no
number is slightly more likely than another. For ordinary groups the page tries up to a few hundred whole shuffles and keeps
the first valid one, which makes every valid draw equally likely. For tight rule sets, where a random shuffle rarely passes,
it switches to a randomized search that always finds a valid draw if one exists; that route is valid but no longer exactly
even across all possibilities.
Why does a hat draw go wrong so often?
Because in a one-shot shuffle the chance that nobody lands on their own name is only about 37%. For any group of six or more, that leaves roughly a 63% chance that at least one person is stuck with themselves.
| People | Valid draws | All shuffles | Share valid |
|---|---|---|---|
| 2 | 1 | 2 | 50.0% |
| 3 | 2 | 6 | 33.3% |
| 4 | 9 | 24 | 37.5% |
| 5 | 44 | 120 | 36.7% |
| 6 | 265 | 720 | 36.8% |
| 8 | 14,833 | 40,320 | 36.8% |
| 10 | 1,334,961 | 3,628,800 | 36.8% |
Source: calculated: derangements D(n) divided by n!.
The figure 1/e (about 0.3679) is the limit of the derangement share as the group grows, and the number of derangements of n items is the whole number nearest n!/e. The usual hat fix, putting the slip back and drawing again, brings its own problem: the last person can end up holding only their own name, and the group starts over. This page checks the complete draw before it shows anyone anything.
Which exclusion rules can a draw handle?
Mutual pairs such as couples, housemates or last year's match all work, provided every person keeps at least one allowed receiver and the exclusions do not squeeze a few people into the same one. Trouble comes from small groups, not large ones.
| Group | Rule | Draw possible? |
|---|---|---|
| 3 people | One couple (A and B) | No: A and B can give to only C, so 2 people would have to share 1 receiver |
| 4 people | One couple | Yes |
| 4 people | Two couples | Yes |
| 5 people | Two couples | Yes |
| 2 people | No trading pairs | No: With two people the only draw is a swap |
| 3 people | One big loop | Yes |
| 4 people | Two couples, one big loop | Yes |
| 4 people | Four exclusions in a square, one big loop | No: No single loop fits these exclusions |
Source: results from this page's own draw function.
When a set is impossible the page names the people who are stuck, so you can remove the exclusion that causes it. Two optional shapes sit under "Couples who can't draw each other". No swaps stops Ann buying for Ben while Ben buys for Ann. One loop puts everyone in a single circle, which is also the ring you can see above.
How private are the reveal links?
Each link carries one person's assignment after the # sign, and a browser does not send that part to the website's server: RFC 3986 says a fragment is handled by the user agent alone. The text is scrambled with a key stored in the link itself. That hides the name from a glance over a shoulder or a chat preview. It is not encryption, and anyone who reads this page's code or studies the link can undo it.
| Item | Where it sits | Who can read it |
|---|---|---|
| Names and rules | The page in your browser, while it is open | You. Nothing is sent to a server. |
| Draw result | The same page memory; gone on reload | You, only if you choose "Show me the chain". |
| Reveal link | After the # in the address, scrambled | Anyone who holds that link and cares to decode it. |
| Page request | The address without the # part | The site, which counts page views. |
| Printed slips | Paper, folded | Whoever unfolds one, and you while printing. |
Source: how this page is built.
You, as the organizer, could decode the links you generate; the page never shows the result unless you press "Show me the chain". Browsers and chat apps may keep links in their history, so anyone with access to a person's phone or messages can open theirs.
How do you run a Secret Santa remotely?
- Collect the names, and ask privately about couples or anyone who should not draw each other.
- Fill in the budget, the exchange date and a note, then press Draw names.
- Send each person only their own link, in a private message. Use "Share" on a phone or "Copy link" on a computer.
- Ask everyone to reply "got it" without naming anyone, so you know each link opened.
- Close the page. The draw is not stored anywhere, which keeps you from peeking later.
If someone drops out, start over with a fresh draw and resend every link. Old links still open the old result, so tell people to delete the earlier message.
What are the common mistakes?
- Pasting every link into the group chat. Then everyone can open everyone's. Copy-all is for you, not the group.
- Forgetting an exclusion until after the draw. Redrawing "because I didn't like it" turns the first result into a rumor. Add the pair first.
- Two people with the same first name. The page refuses duplicates; add a last initial (Ann R., Ann T.).
- A vague budget. "Around twenty" is read as thirty by some people. Put one number and a currency in the budget box.
- Treating a link as a vault. It is a screen against casual peeking. Don't send it somewhere that others can read.
What goes on the slip?
The note you type appears on every reveal and every printed slip. Printed slips are cut apart and folded so the lower half, where the receiver's name sits, tucks behind the giver's name. Thin paper can show through, so fold twice or hold one up to a light before handing them out.
One budget for everyone, in one currency. The exchange date and where it happens. Whether gifts are wrapped, and whether the giver stays secret until opening. Keep it under two lines: the reveal shows it under the name, and the slip prints it once.
Planning more than the draw? Spin the wheel to pick who opens first (the random number generator does the same with numbers), and the Christmas countdown shows how many days are left to buy the gift.
Sources
- Wikipedia: Derangement (counts, and the 1/e limit)
- OEIS A000166: Subfactorial or rencontres numbers
- Wikipedia: Fisher–Yates shuffle
- MDN Web Docs: Crypto.getRandomValues()
- IETF RFC 3986: Uniform Resource Identifier, section 3.5 (fragment)
- MDN Web Docs: URL.hash
- Wikipedia: Hall's marriage theorem (how impossible rule sets are found)
- Wikipedia: Secret Santa
Last reviewed November 16, 2026.