Estimating the value of $e$ using a random function

Generate $N$ random permutations (possibly with Knuth's shuffle).

Then count how many of them are derangements: $N_D$.

Then $$\frac N{N_D}\simeq e$$


Draw $X_i \sim \text{Unif}(1,3)$ and $Y_i \sim \text{Unif}(0,1)$ for $i=1,\ldots,N$. Reject the samples where $Y_i > 1/X_i$. Sort the accepted $X_i$ values and take the $(N/2)$th.

This relies on the observation that $\int_1^e dx/x = 1$. So we do rejection sampling in the rectangle $[1,3] \times [0,1]$ to get points under the $1/x$ curve. By taking the $(N/2)$th smallest value we are finding the point where we have $1/2$ of the original points, that is, area $1$ (observing that the original rectangle has area $2$).

Here is the simulation with $N=10000$ points. The rejected points are in cyan. From the accepted points, the leftmost $N/2=5000$ are in black and the rest are in blue.

Monte Carlo estimation of e


Flip a biased coin $K$ times which has probability of heads $\frac{1}{K}$; let $X_1$ denotes the number of heads that show up. Repeating this process $N$ times gives you $N$ counts of heads $X_1,...,X_N$. Then $$\frac{N}{\Big|\big\{1 \leq i \leq N:X_i=1\big\}\Big|}\approx e$$ when $N$ and $K$ are large.


Pick $N$ random integers $X_1,X_2,\ldots,X_N$ uniformly and independently in $\{1,2,\ldots,N\}$, and then count the number $N_d$ of distinct integers in this list, or equivalently, let

$$ N_d = \#\{X_1, X_2, \ldots, X_N\}. $$

Then for large $N$,

$$ \frac{N}{N-N_d} \approx e. $$

(That is, the size of the random set $\{X_1,\ldots,X_N\}$ is approximately $(1-e^{-1})N$.)