On this page
Pick a random number between 0 and 1. Add another, and keep going until the total is more than 1, then write down how many numbers you used. It is never 1, often 2, sometimes 3, now and then 4 or more.
Play thousands of times and average the counts. The answer settles near 2.718, which is e, the base of natural logarithms, even though nothing in the game mentions logarithms or growth.
How many random numbers does it take to pass 1?
According to Wolfram MathWorld's entry on the uniform sum distribution, the expected number of picks from a uniform distribution on [0,1] needed for the sum to first exceed 1 is e. The same page gives the chance that the total first passes 1 on the nth pick as 1/(n(n − 2)!).
That formula gives these chances for when the game stops:
On the 2nd number: 1/2
On the 3rd number: 1/3
On the 4th number: 1/8
On the 5th number: 1/30
On the 6th number: 1/144
The statistician K. G. Russell described using this game to estimate e by simulation in "Estimating the value of e by simulation", published in The American Statistician in 1991.
How do you set this up in a spreadsheet?
In Excel, RAND returns an evenly distributed random number greater than or equal to 0 and less than 1. Google Sheets has a RAND function that does the same. That is all you need.
In cells A2 to H2, type =RAND() in each. These are eight random numbers for one game.
In I2, count how many it took: =IF(A2+B2>1,2,IF(SUM(A2:C2)>1,3,IF(SUM(A2:D2)>1,4,IF(SUM(A2:E2)>1,5,IF(SUM(A2:F2)>1,6,IF(SUM(A2:G2)>1,7,8)))))).
Select A2:I2 and fill down to row 10001. You now have 10,000 games.
In K1, type =AVERAGE(I2:I10001).
In Excel, press F9 to make new random numbers and watch K1 change. Microsoft's RAND page says the sheet makes new numbers whenever it recalculates.
Eight columns are enough. A game needs more than eight numbers only if eight of them add up to less than 1, and that chance is 1/8!, which is 1 in 40,320 (the reason is in the next section).
Here is what two rows might look like. In the first, the numbers are 0.62, 0.17 and 0.48. The running totals are 0.62, 0.79 and 1.27, so the count is 3. In the second, 0.85 and 0.40 already make 1.25, so the count is 2.
Why is the average e and not 2 or 3?
Turn the question around. The game goes past n numbers only if the first n numbers add up to less than 1.
For one number, that always happens: probability 1.
For two numbers x and y, you need x + y < 1. That is the triangle below the diagonal of a unit square, with area 1/2.
For three numbers, it is a corner of a unit cube, a pyramid with volume 1/6.
For n numbers, the corner piece has volume 1/n!.
There is a standard rule for counts: the average equals the sum of the chances that the count is bigger than 0, bigger than 1, bigger than 2, and so on. The count is always bigger than 0 and bigger than 1, so the average is 1 + 1 + 1/2! + 1/3! + 1/4! + ... That series is exactly e = 2.71828..., the same value listed in OEIS A001113.
So why not 2? The numbers average 0.5, but the game always overshoots 1, and occasional long runs of small numbers pull the average higher.
What should you see when you run it?
You will not get 2.718 exactly. Rick Wicklin of SAS ran 10,000 games and got a mean of 2.7206, close to e but not equal to it.
Try this to see the wobble:
Average only the first 10 rows. Press F9 a few times. The answer jumps around a lot.
Average the first 100 rows. It jumps less.
Average all 10,000. It usually lands within a few hundredths of e.
Use COUNTIF on column I to count the 2s, 3s and 4s. They should come close to MathWorld's exact chances: half, a third and an eighth of your games.
That shrinking wobble is the law of large numbers, which our post on 10,000 simulated coin tosses shows in detail. If you liked getting a constant out of randomness, try how to estimate pi with random points next. For the averaging idea behind it all, see how to calculate the expected value of a game and test it.
If the volume step feels slippery, it is easier to see than to read about. The Fermi Simulation Lab has interactive simulations for ideas like this. The Fermi Concept Library has a lesson for each concept in mathematics, including factorials and series, if you want to go over why 1/n! keeps turning up.



