Back to Pi, nobody seems to have mentioned the "Dartboard Method":
Assuming we have a floating-point random number generator that returns values < 1.0, we simply iterate with
- N = N + 1
- X = rand() * 2 - 1
- Y = rand() * 2 - 1
- D = sqrt(X*X + Y*Y)
- if (D <= 1.0) B = B + 1
The dartboard is a target circle of radius 1 (area PI) in a square of size 2 (area 4). So probability of random throws hitting the circle is PI/4, and thus (4B / N) is an approximation to PI for N sufficiently large.
Convergence is well, shall we say, a tad sluggish. But for algorithmic elegance, it's hard to beat!