VDC Live Demo
Source Code
Issues? Something look weird? Click here and report an issue

Using the van der Corput sequences for bases 2,3 we can generate a sequence of quasirandom points in the unit square. The sequence is said to be low-discrepancy (basically the points are somewhat more uniformly spread across the square; you would expect a truly random sequence of points to have some concentrated lumps and small areas with no points).

quasi-Monte Carlo methods generally have better error properties compared to the standard random and pseudo-random MC methods. As a demonstration, we will estimate π by sampling points in the unit square. The left side shows the VDC estimate using bases 2 (x) and 3 (y). The right side shows the random estimate by repeatedly calling Math.random.

The graphs show the results of sampling many points and estimating PI. Below the graphs, the PI value shows the calculated estimate, "err %" shows the relative error (smaller is better) and "ln err" shows the natural log of the error (smaller is better).

VDC sequences can be "seeded" by setting the starting index for the calculation. In this demo a random integer is chosen using Math.random.

The values and graphs are calculated in your browser window. If the graphs do not appear or the values are not calculated, please report the issue!

VDC (2,3) Sampling


Estimate of PI:
Math.random Sampling


Estimate of PI: