Why does e pop up as the average of "dice rolls" of [0...x[ needed to reach/exceed x?

102 Views Asked by At

I'm refering to my Twitter status here: https://twitter.com/CherryDT/status/859452772542009344

I was testing something yesterday and ended up stumbling upon Euler's constant when I didn't expect it. Can somebody point out to me why? What are the relevant Mathematical rules/principles there? I remember that e plays a role in Stochastic but I don't remember what leads to this.

What I did was essentially measuring how many "rolls" of a die with values between zero and x (exclusive) it takes to get to a sum of at least x points.

Turns out that on average it takes exactly e rolls.

Here's what I did (with random values in the range of [0...1[, rolling until the sum is >= 1):

Demo

1

There are 1 best solutions below

4
On BEST ANSWER

Let $U_1,U_2,\dots$ be iid with uniform distribution on $[0,1]$

For $n=0,1,\cdots$ let $X_n$ take value $1$ if $\sum_{k=1}^nU_k<1$ and let $X_n$ take value $0$ otherwise.

If $N:=\sum_{n=0}^{\infty}X_n$ then $\sum_{k=1}^{N-1}U_k<1$ and $\sum_{k=1}^{N}U_k\geq1$.

Here: $$\mathbb EN=\sum_{n=0}^{\infty}\Pr(X_n=1)=\sum_{n=0}^{\infty}\Pr(U_1+\cdots+U_n<1)=\sum_{n=0}^{\infty}\frac1{n!}=e$$


edit :

Setting $V_{n}:=\sum_{k=1}^{n}U_{k}$ it can be shown with induction that $\Pr\left(V_{n}<x\right)=\frac{x^{n}}{n!}$ for $x\in\left[0,1\right)$.

The base case is evident and the induction step is:

$$\Pr\left(V_{n+1}<x\right)=\Pr\left(V_{n}+U_{n+1}<x\right)=\int_{0}^{x}\Pr\left(V_{n}+U_{n+1}<x\mid U_{n+1}=u\right)du=$$$$\int_{0}^{x}\frac{\left(x-u\right)^{^{n}}}{n!}du=\left[-\frac{\left(x-u\right)^{^{n+1}}}{\left(n+1\right)!}\right]_{0}^{x}=\frac{x^{n+1}}{\left(n+1\right)!}$$