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

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?
I have the answer which is: $$1-(1-k)^2$$ but I don't understand why?

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| 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.

HINT: let $$X$$ and $$Y$$ two independent and uniformly distributed random variables in $$[0,L]$$. Then the probability that you want is $$\Pr[|X-Y|. Then you have that \begin{align*} \Pr[|X-Y| where $$S:=\{(x,y)\in \Bbb R ^2:x\in (y-kL,y+kL)\}$$.

Now note that $$(X,Y)$$ is uniformly distributed in $$[0,L]^2$$, therefore $$\Pr[|X-Y| is the area of $$S \cap [0,L]^2$$ divided by the area of $$[0,L]^2$$.

Alternatively you can check that if $$X$$ and $$Y$$ are independent continuous random variables then for $$Z:=X-Y$$ we have that $$F_Z(c)=\int_{\Bbb R } f_X(s)f_Y(s-c)\,\mathrm d s$$ Therefore \begin{align*} \Pr[|X-Y|