PCG

class PCG64

The Permuted Congruential Generator (PCG) was designed by Melissa O’Neil. The main idea of the PCG is to pass the output of a fast, well-known pseudorandom generator, such as a Linear Congruential Generator (LCG), into a permutation function to enhance its statistical properties. More specifically, the PCG64 (DXSM variant) applies a xor followed by a shift and multiplication on the output of a 128-bit LCG.

PCG is the default generator from the popular NumPy library.

References:

[1] M. E. O’Neill, “PCG: A Family of Simple Fast Space-Efficient Statistically Good Algorithms for Random Number Generation”, Harvey Mudd College, Claremont, CA, HMC-CS-2014-0905, Sep. 2014. [Online]. Available: https://www.cs.hmc.edu/tr/hmc-cs-2014-0905.pdf

[2] DXSM variant. Available: https://numpy.org/doc/stable/reference/random/upgrading-pcg64.html

Note

For the best performance, it is recommended to use a platform and compiler that supports 128-bit integer arithmetic. Otherwise, HighFM must emulate all the operations, which may result in a significant performance loss.

Public Functions

inline PCG64(state_type seed = default_seed, state_type stream = default_stream)

Creates a new instance of the PCG64 generator.

Parameters:
  • seed[in] generator seed (optional)

  • stream[in] generator stream (optional)

PCG64(const PCG64 &other) = default

Creates a new instance of the PCG64 generator from an other instance.

Parameters:

other[in] PCG64 generator to use as the data source

PCG64 &operator=(const PCG64 &other) = default

Copy the internal state from other.

Parameters:

other[in] PCG64 generator to use as the data source

Returns:

*this

virtual ~PCG64() = default

Default destructor.

inline constexpr void seed(state_type seed = default_seed, state_type stream = default_stream)

Reseeds the generator.

Parameters:
  • seed[in] generator seed (optional)

  • stream[in] generator stream (optional)

inline constexpr void set_stream(state_type stream)

Sets the generator stream to a given value.

inline constexpr uint64_t next()

Advances the generator state and generates a new pseudorandom 64-bits integer.

Note

This code was adapted from the NumPy GitHub repository (v1.21.6). See https://github.com/numpy/numpy for the original code.

inline constexpr uint64_t operator()()

Advances the generator state and generates a new pseudorandom 64-bits integer.

Public Static Attributes

static constexpr short bytes = 8

The number of bytes generated.

static constexpr uint64_t max_val = UINT64_MAX

The largest possible value generated.

static constexpr uint64_t min_val = 0

The smallest possible value generated.