Buffon's needle is a statistic experiment created by Comte George-Louis Leclerc (sounds so frenchie).

The principle is to drop needles on a parquet floor and check if the needle cross one of the parquet line (providing each parquet's strip has the same height).

The experiment can be modeled as two random variables representing, for the first, the distance between the center of the needle and the closest parquet line, for the second, the acute angle between the needle and the line. Both random variables follow a uniform distribution, respectively of parameters (0, $latex {\frac{length(needle)}{2}}&s=1$ ) and parameters (0, $latex {\frac{\pi}{2}}&s=1$ ).

A needle cross a line when the angle is superior to 0 and, depending on the previous angle, the distance is less than :

$latex {sin(angle)\times\frac{height(strip)}{2}}&s=2$

Thus, the condition "the needle cross the line" can be summarized by this equation :

$latex {x \leq \frac{l}{2} \sin (\theta)}&s=2$

Where a is the length of the needle, θ the angle and x the distance.

The cool part is that computing the joint probability of the two random variable with the crossing condition gives you an expression of π :

$latex {\pi = \frac{2aN}{ln}}&s=2$

Where N is the number of needle dropped, l the height of a strip and n the number of needle that crossed the line.

Therefore, for a good number of needle drop you can get a value fairly close to π.

The following C# source code is doing precisely that :

using System; namespace BuffonApp { class BuffonNeedles { public static void Main () { // Number of time we will drop a needle const int N = 1000000; // Interval between each line const int a = 10; // Size of a needle const int l = a - 4; // Our random number generator Random r = new Random (); // Number of time we cross the line int n = 0; for (int i = 0; i < N; i++) { double x = r.NextDouble () * (a / 2); double theta = r.NextDouble () * (Math.PI / 2); if (x <= (l / 2) * Math.Sin (theta)) n++; } Console.WriteLine ("Pi approximation : " + ((double)(N * 2 * l)) / (n * a)); } } } 

Which give us a rather good approximate of : $latex {\pi \approx 3,14208745948547}&s=2$