Derangements Calculator (Secret Santa and the Hat-Check Problem)
How many ways n people can each draw somebody else's name, and the chance that a random draw works first time.
Results
The dashed line marks the value you entered.
What this tool does
A derangement is a shuffle where nobody ends up in their own place — a Secret Santa draw where no one picks themselves, or hats handed back at random with nobody getting their own. The count is the nearest whole number to n! ÷ e, and the chance is about 1 ÷ e = 36.8 % almost whatever the size of the group: 4 people give 37.5 % and 10 people 36.79 %. So a random draw fails nearly two times in three, and on average you need about 2.7 draws, which is why people redraw until it works. A group of one has no valid arrangement.
Formula
!n = n! Σₖ (−1)ᵏ ÷ k! = round(n! ÷ e) · chance = !n ÷ n! → 1 ÷ e ≈ 36.8 %
Variables
| Symbol | Meaning | Unit |
|---|---|---|
n | Number of people (or items) | — |
D | Arrangements where nobody gets their own | — |
TT | All possible arrangements | — |
P | Chance that nobody gets their own | % |
PA | Chance that at least one person gets their own | % |
TR | Average number of random draws until one works | — |
Worked example
- Number of people (or items)8
- Arrangements where nobody gets their own14,833
- All possible arrangements40,320
- Chance that nobody gets their own36.788 %
- Chance that at least one person gets their own63.212 %
- Average number of random draws until one works2.72
Limitations
- The calculation runs at full precision and only the display is rounded. If you copy an intermediate value and retype it, small differences can appear.
- The default values are typical reference figures, not measurements of your situation. Replace them with your own data whenever you have it.