Derangement Generator
A derangement is a shuffle where nothing ends up where it started — which is exactly what a secret santa draw needs. The count has a neat recurrence and a startling limit: the share of permutations that are derangements settles at one over e, about 36.8%, and barely moves however many people are involved. So drawing names at random works about a third of the time whether there are five of you or fifty.
What this generator does
Enumerates every permutation with no fixed point, then counts them again with the recurrence D(n) = (n−1)(D(n−1) + D(n−2)) and requires the two to match. It also reports what share of all permutations they represent.
How to use this tool
- Choose how many items are being rearranged.
- Read how many derangements exist against the total permutations.
- Note the share — it hardly changes with size.
- Show the full list to see them all.
Understanding the controls
- How many items
- Between 2 and 7. Every permutation is enumerated, which is factorial work — seven already means checking 5,040.
- Seed
- Chooses which derangement is shown as the example.
- Show the full list
- Lists every derangement rather than just the count and one example.
Common use cases
- Secret santa and gift-exchange draws where nobody gets their own name
- Showing that the probability of a valid draw is independent of group size
- Teaching the inclusion-exclusion principle through a concrete count
- Test cases for shuffle code that must avoid fixed points
- Picking a specific derangement from a seed
How this generator works
Enumeration places each item in turn, skipping its own position, which produces exactly the derangements. The recurrence is computed separately, and the check requires both counts to agree — as well as confirming no derangement leaves anything in place or repeats a value.
Randomness and fairness
Only which derangement is shown as the example is random; the enumeration and both counts are fixed for a given size. Seeded runs pick the same example and are therefore explicitly not cryptographically secure.
For how randomness is produced across the whole site, see how Generate Random works.
Limitations and good to know
- Seven items is the ceiling, because every permutation is enumerated.
- Items are lettered rather than named, so this is the abstract form of a gift-exchange draw.
- Constraints beyond no-fixed-points — couples not drawing each other, for instance — are not supported.
- No draw is performed; this enumerates the possibilities.
- Enumerations are not kept; seed the run to get the same example back.
Privacy and your data
Every permutation is enumerated in your browser. Nothing about the run or your seed is transmitted.
Related generators
- Secret Santa GeneratorDraw fair Secret Santa pairings with exclusions, so nobody draws themselves or an excluded partner.
- Set Partition GeneratorEvery way of splitting a small set into unlabelled groups, counted against the Bell number and broken down by group count.
- Permutation and Combination CalculatornPr and nCr side by side, exactly, with the difference between them worked through rather than assumed.
- Integer Composition GeneratorEvery ordered way to write a number as a sum, counted by enumeration and by the two-to-the-power formula.