You play a game where you sum independent identically distributed uniform random variables over the interval [0,1]. The first time the sum exceeds one, record the count of needed variables. What is the expected number of variables?
Understanding - summation until one
A standard game would unfold like this:
The number of variables, N, takes positive integer values greater than or equal to 0.
Most of the time, when faced with the duty of computing the expected value of N, we would find the probability that N equals a particular integer k. Unfortunately, in our case, this is hardly a straightforward task, and I wholeheartedly commend you if you try and do it.
Since it looks like computing the individual probabilities is rather arduous, how can we proceed from here?
Solution
Let’s start by writing the formula for the expectation of a discrete random variable:
E=i=1∑∞i⋅P(N=i)
=P(N=1)+P(N=2)+P(N=2)+P(N=3)+P(N=3)+P(N=3)+…
=1+P(N>1)+P(N>2)+… Splitting i⋅P(N=i) into a sum of P(N=i) counted i times and aligning the values, we can rewrite the expectation.
The preceding sums, excluding the first being equal to 1, are respectively equal to P(N>k) for each k≥1. It is known that P(N>k)=k!1, so: E(N)=1+k=1∑∞k!1=k=0∑∞k!1=e
Simulations
import randomdef sim_game(): s = 0 count_rounds = 0 while s<1: s += random.uniform(0,1) count_rounds += 1 return count_roundscounts =print(f"Avg rounds: {np.mean(counts)}")