Wednesday, August 3, 2011

e again

I came across a neat quote from Martin Gardner:

The number e is as ubiquitous as pi, turning up everywhere, and especially in probability theory. If you randomly select real numbers between 0 and 1, and continue until their sum exceeds 1, the expected number of choices is e.

-Martin Gardner
note in Calculus Made Easy, p. 153

Of course, this begs for a Python simulation:

import random

def mean(L):
return float(sum(L))/len(L)

def oneTrial():
counter = 1
f = random.random()
while f <= 1:
counter +=1
f += random.random()
return counter

N = int(1E7)
L = [oneTrial() for i in range(N)]
print mean(L)

> python 

A derivation would be nice, but that'll have to wait. I wonder about the variance.

1 comment:

Tobias said...

I think Central limit theorem should help with your derivation