Finding Pi randomly.

Imagine you want to find the ratio between the length of a circunference and its diameter. That's the π (Pi) number. There are several ways to calculate it, but one of my favourite methods is the following one because it's very easy o understand and involves randomness.

Imagine you have a dartboard which actually are circular on a wall (at least where I live are rectangular). Now **throw darts randomly** to the wall. Some darts will hit the dartboard and others will hit the wall. What it's sure is we are going to hit something P(hit_something)=1

OK! But where's π?

P(hit_something) = 1 = P(hit_dartboard)+P(hit_wall)

Strange? It's a problem of areas! The bigger the dartboard is, the easier to hit. So P(hit_dartboard) depends on how big is the dartboard and how small is the wall (a ratio).

OK but where is Pi? The key is the dartboard is circular.

Area of the dartboard. A(dartboard) = radius^2*π

Area of the wall. A(wall) = width*height

So P(hit_dartboard) = A(dartboard)/A(wall) = (radius^2*π)/(width*height).

Solving **π = P(hit_dartboard)*(width*height)/radius^2**

The width and the height of the wall and the radius of the dartboard are constants.

Now the only thing we need is knowing P(hit_dartboard). You can recreate the physical experiment with some slaves and a lot of time or you can simulate it with a computer. It's Simulate Time!

This is a small Java Script widget I've coded to simulate the previous idea. Let's play with it.

Each thrown is represented by a pixel. Red means a hit to the dartboard an blue a fail (hit the wall).

See how π aproaches to it's real value 3,141592 when the throws increase.

Throws | Hits | Calculated π |
---|---|---|

PD: thanks Iris for the image. I'm the one on the bottom right corner!