Halton sequence#
Implements a Halton sequence [[1]], [[2]] which is a low discrepancy sequence [[3]]. A Halton sequence is not a pseudo-random number generator such as Mersenne Twister but a quasi-random sequence. Thus, the output of the Halton sequence appears random and typically the distribution of the generated numbers is more even compared to PRNGs. Care has to be taken regarding multi-dimensional Halton sequence, see 2D Case. Specifically, one must not use a one-dimensional sequence for multi-dimensional applications since the distribution properties do not hold in this case.
Information:
https://stackoverflow.com/questions/42661304/implementing-4-dimensional-halton-sequence
https://people.sc.fsu.edu/~jburkardt/cpp_src/halton/halton.html
https://people.sc.fsu.edu/~jburkardt/c_src/halton/halton.html
Distribution#
(Source code, png, hires.png, pdf)
Fig. 345 Distribution generated using the Halton sequence generating float values.#
(Source code, png, hires.png, pdf)
Fig. 347 Distribution generated using the Halton sequence generating uint32.#
Reference#
-
typedef struct uz_prng_halton_t uz_prng_halton_t#
Object of Halton sequence generator.
-
uz_prng_halton_t *uz_prng_halton_init(uint32_t base_prime)#
Initializes the Halton sequence generator for a given base prime number.
- Parameters:
base_prime – Must be a prime number!
- Returns:
uz_prng_halton_t*
-
float uz_prng_halton_get_uniform_float(uz_prng_halton_t *self)#
Generates one number of a Halton sequence. After n-calls, this function returns the n+1 number in the sequence given the initialization properties.
- Parameters:
self
- Returns:
float
-
void uz_prng_halton_get_uniform_float_2d(uz_prng_halton_t *self, float *x, float *y)#
Generates two numbers, x and y, of the 2D Halton sequence. Returns x and y by pointer, i.e., writes the number of the Halton sequence to the address specified by the arguments *x, *y.
- Parameters:
self
x – Returns x-value of Halton sequence thought pointer
y – Returns y-value of Halton sequence thought pointer
-
void uz_prng_halton_reset(uz_prng_halton_t *self, uint32_t base_prime)#
Resets the Generator to the given base prime number and n-th number in the sequence.
- Parameters:
self
base_prime