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.    

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$.
