The Halton sequence is constructed according to a deterministic method that uses coprime numbers as its bases. As a simple example, let's take one dimension of the two-dimensional Halton sequence to be based on 2 and the other dimension on 3. To generate the sequence for 2, we start by dividing the interval (0,1) in half, then in fourths, eighths, etc., which generates
Equivalently, the nth number of this sequence is the number n written in binary representation, inverted, and written after the decimal point. This is true for any base. As an example, to find the sixth element of the above sequence, we'd write 6 = 1*22 + 1*21 + 0*20 = 1102, which can be inverted and placed after the decimal point to give 0.0112 = 0*2-1 + 1*2-2 + 1*2-3 = 3⁄8. So the sequence above is the same as
To generate the sequence for 3 for the other dimension, we divide the interval (0,1) in thirds, then ninths, twenty-sevenths, etc., which generates
When we pair them up, we get a sequence of points in a unit square:
Even though standard Halton sequences perform very well in low dimensions, correlation problems have been noted between sequences generated from higher primes. For example, if we started with the primes 17 and 19, the first 16 pairs of points: (1⁄17, 1⁄19), (2⁄17, 2⁄19), (3⁄17, 3⁄19) ... (16⁄17, 16⁄19) would have perfect linear correlation. To avoid this, it is common to drop the first 20 entries, or some other predetermined quantity depending on the primes chosen. Several other methods have also been proposed. One of the most prominent solutions is the scrambled Halton sequence, which uses permutations of the coefficients used in the construction of the standard sequence. Another solution is the leaped Halton, which skips points in the standard sequence. Using, e.g., only each 409th point (also other prime numbers not used in the Halton core sequence are possible), can achieve significant improvements.1
In pseudocode:
An alternative implementation that produces subsequent numbers of a Halton sequence for base b is given in the following generator function (in Python).2 This algorithm uses only integer numbers internally, which makes it robust against round-off errors.
Kocis and Whiten, 1997 ↩
Berblinger, Michael; Schlier, Christoph (1991). "Monte Carlo integration with quasi-random numbers: some experience". Computer Physics Communications. 66 (2–3): 157–166. Bibcode:1991CoPhC..66..157B. doi:10.1016/0010-4655(91)90064-R. ISSN 0010-4655. https://www.freidok.uni-freiburg.de/dnb/download/3927 ↩