🪡Buffon's Needle Pi Simulator

Estimate pi by throwing needles

in
in

You Might Also Need

How throwing needles estimates pi

Drop a needle on a floor ruled with evenly spaced parallel lines and the chance that it crosses a line is fixed by the needle length L and the spacing d. When the needle is shorter than or equal to the spacing, that probability is 2L/(pi*d), and rearranging it turns a crossing count into an estimate of pi. This page actually throws the needle as many times as you ask, counts the crossings and reports pi as roughly 2*L*n divided by d times the crossing count. It shows the theoretical crossing probability next to the observed rate, so you can see how far apart the two sit.

Assumptions and what is not covered

The needle centre position and its tilt are each assumed uniform, and the throws are assumed independent. Needle thickness, bounce and rolling are not modelled. The dart style method, which scatters points inside a square and uses the share landing inside a circle, is not covered here. No published standard was found for how many decimal places a given number of throws should reach, so raise the count yourself until the precision you need is stable. The browser Math.random function is not a cryptographically secure random source, so do not use it for draws that carry legal weight or money. Throws are capped at 100,000, and a run with zero crossings shows a notice instead of an estimate. The formula is a classical geometric probability result, written as of October 2026.

Frequently asked questions

Why must the needle be no longer than the line spacing?

The formula used here, 2L/(pi*d), holds only when the needle length is shorter than or equal to the line spacing. When L exceeds d the formula changes, so the page blocks that input and shows a notice.

Why does the same number of throws give a different answer each time?

The needles are thrown with random numbers, so the crossing count changes on every run. More throws tend to pull the estimate toward the true value, but there is no guarantee of accuracy to any given decimal place at a given count.

Can I use this for an official draw?

The browser Math.random function is not a cryptographically secure random source. Do not use it for draws that carry legal weight or money; keep it for learning and reference.