Probability of matching numbers in random sets Hi I am working on a game that involves a set of numbers.  For example lets use the number set of $1$ through $4$.  Suppose I take $1,2,3,4$ and randomize the order and then write them down on a piece of paper directly on top of another set of a random order of set of $1$ through $4$.  How do i figure out the probability of getting $0$ matches, $1$ match, $2$ matches and $4$ matches.  I believe $3$ matches would be impossible since you have $1$ number left so it would default to a match of $4$.
example:
$2 , 1,  3 ,4$
$1,  2,  3, 4$
In this random example above I have $2$ matches.  The $3$ and the $4$ match.  Is there a mathematical formula that I can use to do the math quickly especially for larger sets of numbers for all possible combinations.
Thank you.
 A: 4 numbers:
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 4 1
3 2 1 4
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
I noticed a random set matches 4 numbers 1 time, 2 numbers 6 times, 1 number 8 times and 9 times there are 0 matches.
3 numbers:
1 2 3
1 3 2
3 2 1
2 1 3
2 3 1
3 1 2
I noticed a random set matches 3 numbers 1 time, 1 numbers 3 times, and 2 times there are 0 matches.
As you can see this is very manual and tedious and I figured there must be a better way.
A: Let $d(j)$ denote the number of derangements of a set of $j$ elements. Let $f(n,k)$ the number of permutations of $n$ elements that fix $k$ elements. This can be calculated by taking the product of the number of ways to choose the $k$ elements that we fix and of the derangements of the remaining $n-k$ elements. Thus,
$$f(n,k)={n \choose k}d(n-k)=\frac{n!\sum_{i=0}^{n-k}\frac{(-1)^i}{i!}}{k!}. $$
Dividing out by $n!$ will give you the probability you are looking for.
