Alon Amit on Quora · 2017-06-10

A machine outputs random real numbers between and , until their sum exceeds . How many numbers will it need to generate, on average?

Here's a little trick that's often useful: when a random variable takes on positive integer values, its expectation is

The reason is simple: the probability that it is exactly 7 shows up 7 times in this infinite sum. So overall, this is just the sum of k times the probability of k, which is the expectation.

Why is that useful? You see, when you’re working with a random variable such as “number of times until the sum exceeds 1”, or more generally a “stopping time” or “first success” kind of thing, the probability that it is exactly 7 is a little annoying to calculate: it’s the probability that you didn’t succeed in steps 1 through 6, but then did succeed in step 7. Instead, the probability that it is at least 7 is nothing more nor less than the probability that the first 6 steps failed. This is almost always a simpler expression.

In our case, the chances that you need at least k+1 numbers for the sum to exceed 1 is just the probability that the first k numbers chosen add up to less than 1. This is a simple volume calculation:

Therefore, the expectation we are looking for is simply the sum of 1/k! over all k (including k=0), which is simply e.

Originally posted on Quora: https://qr.ae/pFmdBw