Check the probability that two points on the circle are at least distance 1 apart.

We'll do a Monte Carlo simulation!

In [16]:
"""
`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()
Out[16]:
0.4639907082801117

Now compute a Monte Carlo estimate of the probability that the points are at least distance 1 away.

In [26]:
ntrials = 10^5
wins = 0
for i=1:ntrials
    dist = random_points_distance()
    if dist >= 1.
        wins += 1
    end
end
wins/ntrials
Out[26]:
0.66595
In [25]:
Out[25]:
0.9999999999999998