# Average distance between 2 random points

• Apr 9th 2010, 09:26 PM
jaxon4
Average distance between 2 random points
Here's a problem I've been struggling with:

If I select two numbers at random between 0 and 100 (inclusive and they can be the same number) what is the average difference between these numbers? Assume difference is always positive (i.e. if i select 2 and 40 or 41 and 3 the difference is 38) So if I select 1000000 pairs, what will the average difference be? I'm pretty sure it's less than 50 but I'd like a proof or integral etc...

Ideally I would get a generic solution in the form of "N" where the range is between 0 and N. ( I really want the average between 0 and 1)

Thanks.
• Apr 9th 2010, 10:03 PM
Failure
Quote:

Originally Posted by jaxon4
Here's a problem I've been struggling with:

If I select two numbers at random between 0 and 100 (inclusive and they can be the same number) what is the average difference between these numbers? Assume difference is always positive (i.e. if i select 2 and 40 or 41 and 3 the difference is 38) So if I select 1000000 pairs, what will the average difference be? I'm pretty sure it's less than 50 but I'd like a proof or integral etc...

Ideally I would get a generic solution in the form of "N" where the range is between 0 and N. ( I really want the average between 0 and 1)

Thanks.

Let's assume, for simplicity, that the two points are uniformly and continuously distributed on the entire intervall [0;N].
Suppose you now pick a first point x from [0;N] at random, then this point splits [0;N] into two segments, [0;x] and [x;N].
If you now pick the second point, at random, it will be from the lower intervall with probability x/N and from the upper intervall with probability (N-x)/N.
In the first case, the avarage distance of the second point from the first will be $\tfrac{x}{2}$, while in the second case, the average distance will be $\tfrac{N-x}{2}$.

So, given the first point x from [0;N] the average distance of the second point is $\tfrac{x}{2}\cdot \tfrac{x}{N}+\tfrac{N-x}{2}\cdot\tfrac{N-x}{N}=\tfrac{x^2+(N-x)^2}{2N}$.
You now only have to integrate this, multiplied with the appropriate density function $\tfrac{1}{N}$, with respect to x to get the average distance of two points randomly chosen from the interval [0;N].
• Apr 9th 2010, 10:08 PM
Should be $\frac1{N^2}\int_0^N\int_0^N|x-y|\,\mathrm{d}x\,\mathrm{d}y$ for random real points in [0,N] shouldn't it? If so, then it should come out to N/3, which is less than half, as you thought.
• Apr 9th 2010, 11:17 PM
CaptainBlack
Quote:

Originally Posted by jaxon4
Here's a problem I've been struggling with:

If I select two numbers at random between 0 and 100 (inclusive and they can be the same number) what is the average difference between these numbers? Assume difference is always positive (i.e. if i select 2 and 40 or 41 and 3 the difference is 38) So if I select 1000000 pairs, what will the average difference be? I'm pretty sure it's less than 50 but I'd like a proof or integral etc...

Ideally I would get a generic solution in the form of "N" where the range is between 0 and N. ( I really want the average between 0 and 1)

Thanks.

You are being vague are these reals numbers of integers?

The real number problem is equivalent to choosing two numbers $x,y\sim U(0,1)$ and asking for the mean of $|x-y|$. Well without loss we may assume that $x\sim U(0,1)$ and $y\sim U(0,x)$, then we have:

$E(|x-y|)=2\int_{x=0}^1 \int_{y=0}^x (x-y) \;dydx=1/3$

(the 2 is needed to normalise the probability over the lower half unit square)

CB