The following is inspired from the most recent [riddle of the week](https://www.spiegel.de/karriere/fuenf-baelle-und-fuenf-eimer-raetsel-der-woche-a-6b30bd21-3487-4ecf-aa34-bcd7efe66509) of the German news magazine [Der Spiegel](https://www.spiegel.de).


For any positive integer $n\in\mathbb{N}$, let $[n]$ denote the set $\{1,\ldots,n\}$. Let $E\_n$ be the expected value of the size of the image of any function $f:[n]\to[n]$, or more explicitly, $$E\_n = \frac{1}{n^n}\sum\_{f:[n]\to[n]}|\text{im}(f)|.$$


What is the value of $\lim\_{n\to\infty}E\_n/n$, or, if the limit does not exist, what are the values of $\lim\inf\_{n\to\infty}E\_n/n$ and $\lim\sup\_{n\to\infty}E\_n/n$, respectively?



Approximate size of the image of functions $f:[n]\to[n]$
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}}.$$


Thus, $$\lim\_{n \to \infty} \frac{E\_n}{n}= \lim\_{n \to \infty} 1 - \frac{(n-1)^n}{n^n}=1-\frac{1}{e}.$$


