# How to calculate the probability mass function of $X_N$, the number of people getting back their own hat [duplicate]

How do I calculate the pmf of $X_N$, where $X$ is the number of people out of $N$ getting back their own hat after a random hat exchange?

How can I calculate it without listing all the possible outcomes?

## marked as duplicate by Marc van Leeuwen, Carl Mummert, Shobhit, Jack D'Aurizio, PhoemueXFeb 22 '15 at 19:04

• (Assume everyone got a hat before exchange.) – RHS May 18 '13 at 10:53
• How many people do you have ? if $X$ is discrete then he doesn't have a density function, maybe you are looking for the distribution ? – Belgi May 18 '13 at 10:55
• Right it should be pmf. – RHS May 18 '13 at 10:59
• OK, but The answer still depends on how many people you have – Belgi May 18 '13 at 11:02
• Yes, I will change the $X$ to $X_N$, where $X_n$ could integers be from 0 to N. – RHS May 18 '13 at 11:03

Hint: For $0\leq n\leq N$ : $P(X_{N}=n)$ is the probability that exactly $n$ people got their hat back.
If want to fix some $n$ hats in their place (in how many ways can we choose them ?) and dearrange the other $N-n$ hats (in how many ways can you do that ?)