Library · Geometric Probability · Chapter 1
Three sticks forming a triangle
Problem 1.1
Let be independent uniform random variables in . What is the probability that sticks of lengths form a triangle?
Solution. Three positive lengths form a triangle iff each is less than the sum of the other two. The parameter space is the unit cube , with total volume .
The triangle inequality fails in the region , which is the corner tetrahedron with vertices . Its volume is (one-sixth of the unit cube). By symmetry, the analogous tetrahedra for and also have volume each. These three bad regions are disjoint: at most one side can exceed the sum of the other two.
Hence the bad volume is , and the good volume — the triangle region — is . The probability of forming a triangle is
import numpy as np
a, b, c = np.random.rand(3, 10**7)
p = ((a+b>c) & (b+c>a) & (c+a>b)).mean()
print(f"sim: {p:.5f} exact: 0.5")
# sim: 0.50005 exact: 0.5