PCG Random Number#

Implements the PCG random number generator [[1]]. The Implementation is based on:

The PCG generators have the ability to create independent sub-streams, i.e., use one generator instance with different id’s instead of multiple generators with different seeds. Using different id’s is more efficient w.r.t. memory usage (no multiple instances of the module and state required). However, this feature is not implemented to keep it consistent with the other implemented generators.

Distribution#

The following figures shows the generation of 5000 random numbers using the PCG generator. Additionally, the Histogram of the generated values is shown. The generated random values are uniformly distributed, but not in a perfect manner. The specific pattern and distribution depends on the random seed.

(Source code, png, hires.png, pdf)

../../../../_images/uz_prng_pcg-1.png

Fig. 341 Distribution generated by PCG using seed 0.#

Reference#

typedef struct uz_prng_pcg_t uz_prng_pcg_t#

Object of PCG generator.

uz_prng_pcg_t *uz_prng_pcg_init(uint64_t seed)#

Initializes the PCG number generator for a given random seed. Internally, there is a second value that determines the random stream, which is arbitrarily fixed.

Parameters:
  • seed – Random seed of the generator. Output is deterministic and reproducible for each given seed.

Returns:

uz_prng_pcg_t*

uint32_t uz_prng_pcg_get_uniform_uint32(uz_prng_pcg_t *self)#

Returns a uniformly distributed unsigned integer within 0…UINT32_MAX (i.e., 2^32-1=4,294,967,295)

Parameters:
  • self

Returns:

uint32_t

void uz_prng_pcg_reset(uz_prng_pcg_t *self, uint64_t seed)#

Resets generator to seed.

Parameters:
  • self

  • seed

Sources#