Subfactorial !n — the number of permutations where nothing stays in its own place, exact via BigInt, with the 1/e probability — browser-only
- Runs locally
- Category Calculator
- Best for Getting a realistic range before a purchase, plan, workout, or schedule decision.
Enter a non-negative whole number n. !n (subfactorial) counts the permutations of n items where nothing stays in its original place, computed exactly with BigInt. You also get the factorial n! and the probability !n / n! that a random shuffle leaves no item fixed — which locks onto 1/e ≈ 0.3679 within a few terms.
What this tool does
Free derangement calculator that computes the subfactorial !n exactly with BigInt. A derangement is a permutation in which no element ends up in its original position, so !n counts the rearrangements of n items where every single item moves. The tool uses the recurrence !n = (n − 1)(!(n − 1) + !(n − 2)) with the base cases !0 = 1 and !1 = 0, so the answer is a whole number to the last digit even when the count runs to hundreds of digits. Alongside !n it shows the matching factorial n! and the ratio !n / n!, which is the chance a random shuffle of n items leaves none of them in place. That ratio settles toward 1/e ≈ 0.3679 almost immediately, which is the famous answer to the hat-check problem and to gift-exchange draws where nobody should pull their own name. One-click copy and a shareable URL that reopens the exact value of n. Everything runs in your browser, no upload, no API.
Tool details
- Input
- Numbers
- The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
- Output
- Live result + Copy + Preview
- The result area focuses on usable output, with copy, download, or preview actions when supported.
- Privacy
- Browser-side processing
- The main tool logic does not call an external API, so inputs normally stay in the current tab.
- Save / share
- Shareable URL state
- Key settings are encoded in the URL so another person can reopen the same setup.
- Performance budget
- Initial JS <= 9 KB
- No WASM budget is declared, keeping the tool quick to open on mobile.
- Best fit
- Calculator · Student
- Category and role tags drive related tools, internal links, and quick fit checks.
How to use
-
1. Input
Paste or drop your content into the tool panel.
-
2. Process
Click the button. All processing is local in your browser.
-
3. Copy / Download
Copy the result or download to disk in one click.
How Derangement Calculator fits into your work
Use it for fast estimates, comparisons, and planning numbers before you make the final call.
Calculation jobs
- Getting a realistic range before a purchase, plan, workout, or schedule decision.
- Comparing scenarios by changing one input at a time.
- Turning rough assumptions into a number you can discuss.
Calculation checks
- Double-check units, dates, rates, and rounding assumptions.
- Treat health, finance, tax, and legal outputs as planning aids, not professional advice.
- Save the inputs that produced an important result so you can reproduce it later.
Good next steps
These links move the current task into a more complete workflow.
- 1 Factorial Calculator Exact n! for any non-negative integer, with digit count, trailing zeros, double factorial and scientific notation, computed on BigInt right in your browser Open
- 2 Permutation & Combination Calculator nPr, nCr, n!, n^r and combinations-with-repetition — exact BigInt results with the formula and worked steps — browser-only Open
- 3 Secret Santa Generator Paste your name list, draw who gives to whom, nobody draws themselves, exclude couples, send each match privately, runs in your browser Open
Real-world use cases
Plan a Secret Santa where nobody draws themselves
You are running a gift exchange for n coworkers and want to know how likely a single random draw is to be valid, meaning no one pulls their own name. That likelihood is !n / n!. For a group of 8 the tool shows !8 = 14833 valid draws out of 8! = 40320, about 36.8 percent. So if your draw script just retries on failure, it almost never needs more than three tries, which is a reassuring number to put in front of an impatient office.
Check a probability homework answer exactly
A combinatorics problem asks for the number of ways to mismatch n letters with n envelopes so every letter goes in the wrong envelope. That is the derangement count !n. Type n, read !n as an exact integer, and confirm your hand computation of the recurrence or the inclusion exclusion sum. Because the result is BigInt, your answer for n = 20 stays exact where a calculator using n!/e would show a rounded float.
Teach the 1/e surprise in a stats class
The fact that the chance of a fully shuffled list having no element in place hovers around 36.8 percent regardless of n is a memorable hook. Show students !n / n! for n = 4, 5, 10, 50 and watch it lock onto 0.3679 after just a handful of terms. The side-by-side n! and !n make the convergence concrete rather than a formula on a slide.
Size a randomized assignment or matching test
When you randomly reassign n tasks to n people and want to ensure nobody keeps their old task, the count of clean reassignments is !n and the hit rate of a blind shuffle is !n / n!. Use the number to decide whether rejection sampling is cheap enough or whether you should generate a derangement directly.
Common pitfalls
Confusing !n with n!. The exclamation point comes before n in subfactorial and after n in factorial, and they are different numbers. !4 = 9 while 4! = 24. If a tool or formula gives you the larger number when you wanted derangements, you read the notation backward.
Expecting !1 to be 1. With a single item there is no way to move it off its own position, so !1 = 0, not 1. Only !0 = 1, by the empty-product convention. Many people guess !1 = 1 by analogy with 1! = 1 and get the recurrence base case wrong.
Using !n = n! / e and rounding by hand for large n. The exact rule is !n = round(n! / e), but spreadsheets carry too few digits and the rounded float drifts once n passes about 18. Compute the recurrence on exact integers, as this tool does, to avoid an off-by-one.
Privacy
The whole calculation — the derangement recurrence, the factorial, and the !n / n! probability — is plain BigInt arithmetic running in your browser tab. The value of n never leaves the page and nothing is logged. The one caveat: the shareable link encodes n in the query string, so a link pasted into chat records that number in the recipient server access log. The number n is not sensitive, so this is rarely a concern, but if you would rather not leave a trace, use the copy button and paste the result text instead of the URL.
FAQ
Tool combos
Folks in your role tend to reach for these alongside this tool.
- Chinese Acupoint Locator 200+ meridian acupoints / WHO 2008 standard locations / with contraindications, manipulation, and combinations.
- Affine Cipher Encoder & Decoder Encrypt and decrypt the ax+b affine cipher with live modular-inverse check, browser-only
- Anagram Solver Check if two words are anagrams, rearrange a set of letters into every ordering, and read the sorted letter fingerprint, all in your browser
- Angle Converter Degrees, radians, gradians, turns, arcminutes, arcseconds and NATO mils, all from one input, copyable, browser-only