pi-thon – blip on 2026-03-11

Inspired by this Matt Parker video, some bad python code to approximate pi:

from random import random
from math import ceil, gcd, sqrt

upper = 1<<32
count = 1<<24

p = sum(gcd(ceil(random()*upper),ceil(random()*upper))==1 for _ in range(count))/count
print(f"{p=} pi={sqrt(6/p)}")

I got a approximation of 3.141475812850102.

Back to index of blips