Let's say we have a circle circumscibed onto a square. Here the area of the circle is \( A(\text{circle})=\pi r^2 \) and the area of the square is \( A(\text{square})= 4r^2 \). The ratio of the area of the circle to the area of the square is then
\( \frac{A(\text{circle})}{A(\text{square})}= \frac{\pi r^2}{4 r^2} = \frac{\pi}{4} \).
Let's approximate this ratio by asking: if we randomly threw points in the area of the square, what is the ratio of points that land in the circle to the total number of thrown points.
\begin{align}
\frac{A(\text{circle})}{A(\text{square})}
&= \mathbb{E} \bigg[ \frac{\text{num_points_inside_circle}}{\text{tot_num_points}} \bigg] \\
&\approx \sum_i^N \bigg( \frac{\text{num_points_inside_circle}}{\text{tot_num_points}} \bigg) \\
&\approx \frac{1}{N} \sum_i^N \bigg( text{num_points_inside_circle} \bigg) \\
&\approx \frac{1}{N} \sum_i^N (x_i^2 + y_i^2 \leq r^2) \\
&= \text{sample_ratio}
\end{align}
Typically, this example is used to approximate \( \pi \), because as this sample ratio gets better, we have that it equals \( \frac{\pi}{4} \). Therefore, we can just approximate \( \pi \) as \( \pi = 4 \cdot \text{sample_ratio} \) .