Probability that the distance between two random points on a line segment $L$ is less than $kL$, where $0<k<L$

probability

I have this question and I can not solve.
Suppose I have a line segment of length $L$. I now select two points at random along the segment. What is the probability that the distance between the two points is less than kL, where $0<k<L$?
I have the answer which is:
$$1-(1-k)^2$$
but I don't understand why?
Can you please help.

Best Answer

Here’s a rather informal answer to the problem. Consider a bijection of choosing the two points onto a point on a plane.

The purple region represent the possible locations of $X$ and $Y$. For instance $(0.2,0.4)$ means that point $X$ has distance $0.2L$ from one end and $Y$ has $0.4L$.

Now we want $XY$ to be less than $kL$. That is essentially saying that $|x-y|<k$ in our plane, which corresponds to the blue region, i.e. a hexagon with vertices $(0,0),(0,k),(1-k,1),\ldots$.

To calculate the probability, we then just have to find the area of the blue region divided by the purple one, and the answer of $$1-(1-k)^2$$ follows from direct computation.