This is the 2D counterpart of the 3D sphere-in-cube quasi-Monte Carlo race: the same pseudorandom-vs-Halton contest, but run as a genuinely planar integration problem with its own exact discrepancy readout, not a flattened view of the 3D scene. The box is the square [-1,1]² (area 4) and the target is the inscribed unit circle (area π):
P(inside) = π / 4
π̂ = 4 · (points inside circle) / (total points)
Plain pseudorandom sampling (each coordinate from Math.random()) has estimator error that shrinks only as O(1/√N). The Halton sequence instead builds each coordinate deterministically via the van der Corput construction in bases 2 and 3, spreading points evenly across the square from the very first samples:
vdC(i, b) = Σ dₖ(i) · b^(-k-1) (digits of i in base b, reversed after the point)
Halton point i = ( vdC(i,2), vdC(i,3) )
Rather than only comparing π estimates, this simulator also computes the star discrepancy D*ₙ directly — the quantity low-discrepancy sequences are actually named for. For every sample point pᵢ = (x,y) in the unit square, it checks the anchored box [0,x)×[0,y) and measures how far the empirical point count in that box deviates from its expected area:
D*ₙ = max over anchor points p=(x,y) of | Fₙ([0,x)×[0,y)) − x·y |
A lower D*ₙ means the point set leaves fewer gaps and clumps than a perfectly uniform distribution would predict — the Halton set's D*ₙ is consistently a fraction of the pseudorandom set's at equal N, which is exactly why quasi-Monte Carlo sequences are preferred for expensive high-dimensional integrals in finance and rendering. The discrepancy grid overlay shows the same effect visually: each cell is shaded by how far its point count deviates from the uniform expectation, so the pseudorandom panel shows visibly patchy cells while the Halton panel stays close to flat.
- Points per frame — how many new samples both sequences draw each animation frame.
- Play/Pause, Reset — control and restart the sampling run.
- Show discrepancy grid — toggle the 10×10 cell-deviation overlay used for the visual comparison.