Library · Geometric Probability · Chapter 10
Expected minimum distance to the boundary of a square
Problem 10.1
A point is chosen uniformly at random in the unit square . What is the expected minimum distance from to the boundary of the square?
Solution. The minimum distance from to the boundary is Write and , so .
The random variable is uniform on , and satisfies iff or , so for . Hence is uniform on , with density . Similarly is uniform on , independently of .
Now where are iid uniform on . For iid uniforms on , With :
The same calculation in one dimension (distance from random point in to its nearest endpoint) gives ; in three dimensions (cube) it gives ; in general dimension it is . The factor arises because we take the minimum over coordinate-distances, and folding by the midpoint makes each “half-coordinate” uniform on .
import numpy as np
x, y = np.random.rand(2, 10**7)
d = np.minimum(np.minimum(x, 1-x), np.minimum(y, 1-y))
print(f"sim: {d.mean():.5f} exact: {1/6:.5f}")
# sim: 0.16664 exact: 0.16667