How do we calculate the chances of getting n fixed points in a permutation? I understand that attaining a derangement for n = 4 or more objects has a probability of about 1/e or about 37 %. But what about permutations with precisely n fixed points? For example, if I have exactly ten cards (numbered 1 to 10), shuffle them and then lay them out in a row, what are the chances of getting one fixed point, two fixed points, ..., 10 fixed points?
My attempt for (say) 4 fixed points is: (10!)(10C6)(1/e).
But I cannot convince myself this is correct.    
 A: Let $D_n$ denote the number of derangements (fixed-point-free permutations)
of an $n$-element set. Then $D_n/n!\to e^{-1}$; indeed
$$D_n=n!\sum_{k=0}^n\frac{(-1)^k}{k!}.$$
The number of permutations of an $n$-element set with $k$ fixed points
is
$$\binom nk D_{n-k}.$$
For a fixed $k$, as $n\to\infty$ the probability of a random permutation
having $k$ fixed points converges to $e^{-1}/k!$. So for large $n$
the distribution of the number of fixed points is approximately
Poisson of mean $1$.
A: After some serious searching, I was able to find some proper formulas.  First, the number of derangements !n of n terms is given by
$$!n=\lfloor \frac{n!+1}{e}\rfloor$$
Next, the probability of $r$ fixed points in a permutation of $n$ terms is given by
$$\mathrm{Pr}(n,r)=\frac{!(n-r)}{r!(n-r)!}$$
Finally, you can multiply that probability by the total number of permutations $n!$ to get the number of permutations with r fixed points:
$$\operatorname{FP}(n,r)=\frac{!(n-r)}{r!(n-r)!}\ast n!$$
References:
https://en.wikipedia.org/wiki/Derangement#Counting_derangements
https://groupprops.subwiki.org/wiki/Probability_distribution_of_number_of_fixed_points_of_permutations
A: Denote by $F(n,k)$ the number of permutations of $n$ elements with exactly $k$ fixed points. It satisfies the following relations.


*

*$F(n,n)=1$ given by the identity permutation.

*$F(n,k) = \binom{n}{k}F(n-k,0)$ given by choosing $k$ points to fix and then taking a permutation of the other elements with no fixed points.

*$\sum_{k=0}^nF(n,k) = n!$


This is enough to compute $F(n,k)$ recursively. Here's an ugly python code finding $F(n,k)$.
import math
import scipy.special

n_fixed_points = {(0,0):1}

def F(n,k):
    if n_fixed_points.has_key((n,k)):
        return n_fixed_points[(n,k)]
    if k==n:
        n_fixed_points[(n,k)] = 1
        return 1
    if k>0:
        f = scipy.special.binom(n,k)*F(n-k,0)
        n_fixed_points[(n,k)] = f
        return f
    f = math.factorial(n)-sum([scipy.special.binom(n,i)*F(n-i,0) for i in xrange(1,n+1)])
    n_fixed_points[(n,k)] = f
    return f

print F(10,4)

It gives $F(10,4) = 55650$.
