This is actually a rather tricky problem.
We have a stick of length 1.
We uniformly select a value x and break the stick there.
Either \(x < \frac{1}{2}\) or \(x >= \frac{1}{2}\) .
Without loss of generality, let’s assume \(x < \frac{1}{2}\).
(We will then double the result from this case to obtain the final answer.)
Since \(x < \frac{1}{2}\), it represents the length of the shorter stick, which we will not break further.
We have a longer stick of length \(1-x >= \frac{1}{2}\), which we will break into lengths \(y\) and \(z=1-x-y\) .
Thus we will have 3 sticks with lengths \(x\), \(y\), and \(z=1-x-y\) .
We know from the triangle inequality that the length of each of the above must be less than \(\frac{1}{2}\) for the sticks to make a triangle.
The result depends on how close the length of the first stick is to \(\frac{1}{2}\) .
If \(x\) is just short of \(\frac{1}{2}\) , then \((1-x)\) is just slightly bigger than \(\frac{1}{2}\), and a uniform cut along this stick makes it highly likely that both pieces will have length less than \(\frac{1}{2}\) .
On the other hand, if \(x\) is extremely short, then \((1-x)\) is much bigger than \(\frac{1}{2}\), and it is much more likely that a cut on this larger stick would yield one piece which has length more than \(\frac{1}{2}\), making it impossible to form a triangle.
In fact, the probability that the cut to the second stick would give pieces of the desired size depends upon the ratio of the lengths of the two sticks from the first cut, \(\frac{x}{1-x}\) .
(An explanation is given in: Joe Whittaker, “Random triangles”, in American Mathematical Monthly, 97(3):228-230, March 1990, available at https://www.jstor.org/stable/2324691 )
We need to solve \({\int\limits _{ 0 }^{ { 0.5 } }{ \frac { x }{ 1-x } \mathrm{d}x }}\) .
Substituting \(u = 1-x\) ; \(du = -dx\) we obtain
\[ \begin{aligned} \int\limits _{ 0 }^{ { 0.5 } }{ \frac { x }{ 1-x } \mathrm{d}x } &=\int\limits _{ u=1 }^{ _{ u={ 0.5 } } }{ \left[ \frac { 1-u }{ u } (-\mathrm{d}u) \right] } \\ &=\int\limits _{ { u={ 0.5 } } }^{ u=1 }{ \left[ \frac { 1-u }{ u } \mathrm{d}u \right] } \\ &=\int\limits _{ { u={ 0.5 } } }^{ u=1 }{ \left[ \frac { 1 }{ u } -1 \right] \mathrm{d}u } \\ &=\left[ \log u-u \right] _{ u={ 0.5 } }^{u=1} \\ &=\log 1 - 1 - \log 0.5 + 0.5 \\ &= 0 -1 + \log 2 + 0.5 \\ &= \log2 - \frac{1}{2} \end{aligned}\]
As this is the result for the case where \(x < \frac{1}{2}\), we have to double it in order to obtain the final result:
\[ 2 \log 2 - 1 \approx 0.386294 \]
n = 1000000
x = runif(n) # x will be the first cut point.
a = b = c = matrix(0,n,1) # create dummy matrices for the three final sticks
#y = matrix(0,n,1) # create dummy matrix of y: all zeros
#z = matrix(0,n,1)
for (i in 1:n) {
if(x[i] < 0.5) {
# if x is less than 1/2, then we will cut the other stick, which has length 1-x
a[i] = x[i] # designate the short stick as "a"
b[i] = runif(1,0,1-x[i]) # generate a random length for b[i], where b[i] is between 0 and 1-x[i]
c[i] = 1-a[i]-b[i] # the remaining portion of 1-x
}
else {
# if x is greater or equal to 1/2, then we will cut x
a[i] = 1-x[i] # the short stick which we will not cut
b[i] = runif(1,0,x[i]) # generate a random length for b[i], where b[i] is between 0 and x[i]
c[i] = 1-a[i]-b[i] # the remaining portion of x
}
}
# true/false array determining which cases can form a triangle
is_triangular = ( ( a+b > c ) & ( a+c > b ) & (b+c > a ))
### The number of simulations where the cuts resulted in lengths that could form a triangle:
answer = sum(is_triangular)
answer## [1] 386242
## [1] 386294