You Can Calculate Pi with Random Numbers and Python

Rhett Allain
9 min readMar 2, 2024
Photo: Rhett Allain. Illustration of the Monte Carlo method for calculating Pi.

Pi is a magical number. There’s no doubt about that. The two coolest things for me are that it’s irrational (goes on forever) and that it shows up in a bunch of weird places in physics (here’s the explanation of why).

Pretty much everyone knows the first few digits of Pi — like 3.1415 (maybe you even know more). But how do we find these values? We could use the most…

--

--

Rhett Allain

Physics faculty, science blogger of all things geek. Technical Consultant for CBS MacGyver and MythBusters. WIRED blogger.