No, I was confused too. The maths doesn't make sense to me and the whole blog seems to exist just to push amazon affiliate links.
If you are actually interested in probability theory, I highly recommend this (non-affiliate-link) book:
http://www.amazon.co.uk/Probability-Computing-Randomized-Alg...
It does a good job of motivating the subject by applying the new theory in each chapter to the study of useful randomized algorithms.
import random
totalsteps = 0
for i in range(100000000):
sum = 0.0
steps = 0
while sum < 1.0:
sum += random.random()
steps += 1
totalsteps += steps
print('AVG STEPS: ' + str(totalsteps / i)) perl -e 'my $testcount = 10_000_000; my $total = 0; foreach my $i (0 .. $testcount) { my $sum = 0; while($sum < 1) { $sum += rand(); ++$total } } print $total / $testcount'
2.7186292 (average (map-n (fn ()
(1+ (position-if (let1 x 0
(fni (< 1.0 (incf x (random 1.0)))))
(range 100))))
10000))EDIT: Beaten to it :)
One way to arrive at the answer correctly is to write the number of samples needed before they first sum to 1 as N and observe that the probability that P[N > k] = 1/k!. You can get this from a k-dimensional integral. A general formula for E[N] is Sum_k=0^infty P[N > k] thus E[N] = e.