Skip to content
← Back to all questions
FreeProbabilityMedium

Uniforms Until the Sum Exceeds One

Asked atFive RingsJump Trading

Question

Draw random numbers uniformly from [0,1][0, 1], one at a time, and keep a running total. Stop as soon as the total is greater than 11. Let NN be the number of draws. Find E[N]E[N].

Solution

Try it yourself first. Open a hint if you get stuck.

Hint 1

N>nN > n means the first nn draws add up to at most 11. Find P(U1+⋯+Un≤1)P(U_1 + \dots + U_n \le 1) for n=1,2n = 1, 2 by drawing a picture.

Hint 2

For a count NN, E[N]=P(N>0)+P(N>1)+P(N>2)+…E[N] = P(N > 0) + P(N > 1) + P(N > 2) + \dots

Show solution

Call the draws U1,U2,…U_1, U_2, \dots

Step 1: When do we need more than nn draws? We are still going after nn draws exactly when the total so far has not passed 11:

N>n  ⟺  U1+U2+⋯+Un≤1.N > n \iff U_1 + U_2 + \dots + U_n \le 1.

So we need pn=P(U1+⋯+Un≤1)p_n = P(U_1 + \dots + U_n \le 1).

Step 2: Why pn=1n!p_n = \dfrac{1}{n!}.

Small cases first. p1=P(U1≤1)=1p_1 = P(U_1 \le 1) = 1. For n=2n = 2, the point (U1,U2)(U_1, U_2) is uniform in the unit square, and U1+U2≤1U_1 + U_2 \le 1 is the triangle below the diagonal: half the square, so p2=12p_2 = \tfrac12.

The general case, by sorting. Look at the running totals

S1=U1,S2=U1+U2,…,Sn=U1+⋯+Un.S_1 = U_1, \quad S_2 = U_1 + U_2, \quad \dots, \quad S_n = U_1 + \dots + U_n.

The event Sn≤1S_n \le 1 says these totals are nn points in [0,1][0, 1] that come out in increasing order: S1<S2<⋯<Sn≤1S_1 < S_2 < \dots < S_n \le 1.

Now compare with nn independent uniform points V1,…,VnV_1, \dots, V_n in [0,1][0, 1]. Two facts:

  1. Turning the draws (U1,…,Un)(U_1, \dots, U_n) into the totals (S1,…,Sn)(S_1, \dots, S_n) is a one-to-one change of variables that keeps volume the same (each SiS_i just adds the earlier draws, a shear). So "the totals land in increasing order inside [0,1][0,1]" has the same probability as "V1<V2<⋯<VnV_1 < V_2 < \dots < V_n".
  2. The nn points V1,…,VnV_1, \dots, V_n can come out in n!n! different orders, all equally likely, so one particular order has probability 1n!\frac{1}{n!}.

Therefore

P(N>n)=pn=1n!.P(N > n) = p_n = \frac{1}{n!}.

Check: n=2n = 2 gives 12\tfrac12, matching the triangle; n=3n = 3 gives 16\tfrac16, the corner pyramid of the cube.

Step 3: From these probabilities to E[N]E[N].

Why we can add the P(N>n)P(N > n) instead of multiplying by nn. The definition is E[N]=∑nn P(N=n)E[N] = \sum_n n \, P(N = n). The shortcut rewrites nn as a count:

N=1+1+⋯+1⏟N ones=1(N>0)+1(N>1)+1(N>2)+⋯N = \underbrace{1 + 1 + \dots + 1}_{N \text{ ones}} = \mathbf{1}(N > 0) + \mathbf{1}(N > 1) + \mathbf{1}(N > 2) + \cdots

because N>kN > k is true for exactly NN values of kk, namely k=0,1,…,N−1k = 0, 1, \dots, N - 1. Taking expectations of both sides,

E[N]=P(N>0)+P(N>1)+P(N>2)+⋯E[N] = P(N > 0) + P(N > 1) + P(N > 2) + \cdots

Each draw count nn still gets weighted by nn; it's just collected one layer at a time.

Shortcut:

E[N]=∑n=0∞1n!=1+1+12+16+124+⋯=e.E[N] = \sum_{n=0}^{\infty} \frac{1}{n!} = 1 + 1 + \frac12 + \frac16 + \frac1{24} + \cdots = e.

Same answer the long way. P(N=n)=P(N>n−1)−P(N>n)=1(n−1)!−1n!=n−1n!P(N = n) = P(N > n - 1) - P(N > n) = \frac{1}{(n-1)!} - \frac{1}{n!} = \frac{n - 1}{n!}. Then

E[N]=∑n=2∞n⋅n−1n!=∑n=2∞1(n−2)!=1+1+12+16+⋯=e.E[N] = \sum_{n=2}^{\infty} n \cdot \frac{n-1}{n!} = \sum_{n=2}^{\infty} \frac{1}{(n-2)!} = 1 + 1 + \frac12 + \frac16 + \cdots = e.

Answer: E[N]=e≈2.71828E[N] = e \approx 2.71828.

Sanity check: each draw averages 12\tfrac12, so you might guess 22 draws. But you always need at least 22, and sometimes 33 or more, so the average has to be above 22.