RNG class

Pseudorandom number generator.

Adapted from minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org Licensed under Apache License 2.0 (NO WARRANTY, etc. see https://www.pcg-random.org/download.html)

Also the PBRTv4 and Wenzel Jakob's pcg32 libraries.

Adapted to include some convenience functions for darts types like Vec2f, and Vec3f.

Public functions

auto rand1u() -> uint32_t
Generate a uniformly distributed unsigned 32-bit integer.
auto rand1u(uint32_t range) -> uint32_t
Generate a uniformly distributed unsigned 32-bit integer in [0, range[.
auto rand2u() -> Vec2u
Generate a Vec2u where each component is a uniformly distributed unsigned 32-bit integer.
auto rand3u() -> Vec3u
Generate a Vec3u where each component is a uniformly distributed unsigned 32-bit integer.
auto rand4u() -> Vec4u
Generate a Vec4u where each component is a uniformly distributed unsigned 32-bit integer.
auto rand1f() -> float
Generate a single precision floating point value on the interval [0, 1)
auto rand2f() -> Vec2f
Generate a Vec2f where each component is uniformly distributed in [0, 1)
auto rand3f() -> Vec3f
Generate a Vec3f where each component is uniformly distributed in [0, 1)
auto rand4f() -> Vec4f
Generate a Vec4f where each component is uniformly distributed in [0, 1)
template<typename Iterator>
void shuffle(Iterator begin, Iterator end)
Draw uniformly distributed permutation and permute the given STL container.
void advance(int64_t delta_)
Multi-step advance function (jump-ahead, jump-back)
auto operator-(const RNG& other) const -> int64_t
Compute the distance between two PCG32 pseudorandom number generators.
auto operator==(const RNG& other) const -> bool
Equality operator.
auto operator!=(const RNG& other) const -> bool
Inequality operator.

Function documentation

template<typename Iterator>
void RNG::shuffle(Iterator begin, Iterator end)

Draw uniformly distributed permutation and permute the given STL container.

From: Knuth, TAoCP Vol. 2 (3rd 3d), Section 3.4.2

void RNG::advance(int64_t delta_)

Multi-step advance function (jump-ahead, jump-back)

The method used here is based on Brown, "Random Number Generation with Arbitrary Stride", Transactions of the American Nuclear Society (Nov. 1994). The algorithm is very similar to fast exponentiation.