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

This question already has an answer here:

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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

• (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

## 1 Answer

Hint: For $0\leq n\leq N$ : $P(X_{N}=n)$ is the probability that exactly $n$ people got their hat back.

In how many ways this can be done ?

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 ?)

• Thank you. But I think what you just did was rewriting my question. Also n is from 0. Means no one getting there own hat. – RHS May 18 '13 at 11:42
• I think maybe you could show how to get the pmt of N=4 as an example. – RHS May 18 '13 at 12:06
• @RHS - this is not a rewrite to your question. the hints are in the last paragraph. Note that the word "dearrange" is a link to guide you do find the number of permutations without fixed points – Belgi May 18 '13 at 12:35