http://www.perlmonks.org?node_id=58805


in reply to Re: Accuracy of Random Pi
in thread Pi calculator

I'm not sure if setting srand would really help the situation. In order for the Monte Carlo method to be most effective the random numbers produced must be the most evenly spread out. In fact, you can be more accurate without random numbers and instead going through all four corners, then their mid-points, and their mid-points' mid-points, e.g. :
. . . . . -> . . . -> etc. . . . . .

However, if you would like to use random numbers you need one of two types of random numbers. You either need true even-bias random numbers (pseudo-random can work but often don't :) ). Or you can use a particular kind of random numbers that are designed not to repeat and are garunteed to be spread evenly and more and more closely together (very similar to the systematic approach above).

Two examples are Hamilton and Sobol sequences. If you use them, you get a 1/N convergence, instead of a 1/N^2 (which you get for uniform numbers since there is nothing that keeps them from clumping up). I was going to give below "Numerical Recipe's in C"'s version of Antonov-Saleev's variant on Sobol's sequence. However it's simply too long. Also, I have to wake up for work tomorrow, and the first version I typed in (converting it to Perl from C) didn't work just right. Oh well.

Good luck, Hamilton sequences are much easier to do.

Ciao,
Gryn