We'll do a Monte Carlo simulation!
"""
`random_points_distance()`
=========================
Return the euclidean distance of two points
generated at random on the unit circle.
"""
function random_points_distance()
phi1 = 2*pi*rand() # random angle
phi2 = 2*pi*rand()
p1 = [cos(phi1),sin(phi1)] # x,y coords of pt 1
p2 = [cos(phi2),sin(phi2)] # x,y coords of pt 2
return norm(p1-p2)
end
random_points_distance()
Now compute a Monte Carlo estimate of the probability that the points are at least distance 1 away.
ntrials = 10^5
wins = 0
for i=1:ntrials
dist = random_points_distance()
if dist >= 1.
wins += 1
end
end
wins/ntrials