How to find pi in randomness all around you


Celebrate Pi Day and read all about how this number pops up across math and science on our special Pi Day page.

Grab something circular, like a cup, measure the distance around the circle, and divide that by the distance across the widest part. What you’ll get is a pretty good estimate of the irrational number pi (3.14159…). But you can also find pi in a series of random coin flips or a collection of needles tossed on a wooden floor. Sometimes the reason pi shows up in randomly generated values is obvious—if there are circles or angles involved, pi is your guy. But sometimes the circle is cleverly hidden, and sometimes the reason pi pops up is a mathematical mystery!

To celebrate Pi Day this year, here are three ways to estimate pi using random chance that you can try out at home. The last one, using coin flips, is brand new—published just in time for Pi Day.


On supporting science journalism

If you’re enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.


1. Circle in a square

Perhaps the simplest way to randomly estimate pi works like this: take a square with side length 2 and place a circle with radius 1 inside so that it just touches the edges of the square. Then randomly generate points in the square. As you add more and more random points, the proportion of points which end up in the circle will approach π4—the ratio between the area of the circle (pi) and the area of the square (4).

The incidence of pi here is not surprising—it comes directly from the formula for the area of a circle—but the method is a classic example of a Monte Carlo simulation, in which random data are used to approximate an exact calculation.

Graphic shows how a unit circle with a radius of 1 inside a 2-by-2 square containing 500 randomly generated points can be used to estimate the value of pi.

2. Buffon’s Noodle

Suppose I drop a bunch of needles on a hardwood floor with lines spaced one needle length apart. What proportion of the needles can I expect to cross the lines? This question was first posed by Georges-Louis Leclerc, Comte de Buffon (or Count of Buffon) in 1733, and the answer is 2π (about 23).

To find out why, we need to think about a more general question: What if our needle is not a straight line but a squiggle, a square or any other line-drawn shape?

This extended version of the problem is sometimes called “Buffon’s noodle” because noodles come in many more shapes than needles. It turns out that no matter what shape the needle is bent into, we can still expect it, on average, to cross the same number of lines. The expected value of the number of lines crossed is proportional to the length of the needle. In other words, we can expect a collection of needles of length n (of any shape) to cross n times as many lines as the same number of needles of length 1.

So to find the answer to Buffon’s query, all you need to do is pick a clever shape for your needles. This is where the circles come in. If you have lines spaced one unit apart and a needle bent into a circle that has diameter 1, it will always cross the lines exactly twice. The length of the needle making up the circle is pi, and so the probability that a needle of length 1 will cross a line will be the expected value of the number of times the circle crosses—2—divided by the length of the circular needle, giving us 2π.

Graphic shows how a square overlaid with evenly spaced horizontal lines and 500 randomly scattered needles of the same length as the space between the lines can be used to estimate the value of pi.

3. Flipping coins

Pick up a coin and flip it. Record heads or tails. Repeat until you’ve gotten one more head than tails, and record the proportion of heads to total flips. For example, if your first flip was heads, stop right away and record 1. If you flip tails, heads, tails, heads, heads, stop and record ⅗. The expected value of your result, or the average of all your trials if you did infinitely many, is π4. The more trials you average together, the closer you get to π4.

This new method for estimating pi using coin flips was introduced by James Propp, a mathematician at University of Massachusetts Lowell, in a preprint posted online at ArXiv.org last month—just in time for Pi Day! Though the math behind the method is nothing new, the idea to use it to estimate pi with coin flips is.

So why do we get π4? The unsatisfying answer is that somewhere in the probability calculation there is an infinite sum that happens to correspond to the values of the arcsin function—a trigonometric function closely related to pi. But mathematicians haven’t found a meaningful connection between flipping coins and pi. “Sometimes something that’s really basic has relevance to two totally disconnected branches of mathematics,” Propp says. “That’s one of the joys of mathematics, but in many respects it’s a mystery.”

Graphic shows how five sequences of coin flips can be used to estimate the value of pi.

Vienna University of Technology mathematician Stefan Gerhold observed a very similar result, which he posted as a preprint to arXiv.org in 2025. Instead of flipping a coin until you have more heads than tails, Gerhold and his co-author were thinking about families having children and stopping when they had one more boy than girl. “It’s very mysterious,” Gerhold says. “I don’t think there is a good way to understand that [in this scenario] the expectation will involve pi.”

None of these methods are particularly practical for estimating pi’s value. To get pi to the accuracy of 3.14, Propp estimates it might take up to one trillion coin flips. This is partially because sequences of coin flips can get really long before heads overtake tails, so much so that the expected value of a sequence’s length is infinity! On top of that, you can’t flip all the coins at once the same way you can drop needles—the order of heads and tails matters. That’s why Propp suggests trying it in a classroom, where many students can flip sequences of coins simultaneously.

Jennifer Wilson, a mathematician at the New School, who uses similar probability models to analyze voting methods, finds the result pleasing. “It’s nice because it’s certainly something you could try with any group of students, and all you’d need is a background in calculus to understand it.”

On your own, you might be flipping coins for quite a while to get an accurate read on pi. And even the other two methods might require around one million random points or needle drops to get 3.14—but you could get luckier. This Pi Day, consider joining in on the tradition of finding the value of pi in wildly inefficient ways.



Source link

depress heavy taut

Law enforcement shuts down botnet made of tens of thousands of hacked routers

Leave a Reply

Your email address will not be published. Required fields are marked *