Using the Monte Carlo method.
Basically, you inscribe a circle in a square with sides of arbitrary length. You know that the area of the square is the square of the length of its side. You assume that the area of the circle is some unknown constant times the square of its radius (the radius is half the length of the side of the square). This unknown constant is pi. The ratio of the area of the circle to the area of the square is then pi/4.
Let’s say that the square is centered on a Cartesian plane, so that its vertices are at (-0.5, 0.5), (0.5, 0.5), (0.5, -0.5), and (-0.5, -0.5). You can use a psuedo-random number generator to randomly plot points within that set of coordinates. A certain percentage of points will fall inside the perimeter of the circle. Given enough points, the percentage that falls inside of the circle will be proportional to the ratio of the area of the circle to the area of the square.
So this means that you can approximate pi by dividing the number of points that randomly fall within the circle by the total number of randomly generated points, and then multiplying that number by 4.
Here’s a video that explains it better.