For each $i \in [n]$, the probability that $i$ is in the image of a random function $f: [n] \to [n]$ is $1 - \frac{(n-1)^n}{n^n}$. By linearity of expectation, the expected size of the image of $f$ is $$n-\frac{(n-1)^n}{n^{n-1}}.$$
Tony Huynh
- 32.1k
- 11
- 112
- 187