Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
Pseudorandom Number Generator (xoshiro256++)

Introduction

prng_xoshiro is a constexpr-friendly pseudorandom number generator implementing the xoshiro256++ algorithm, designed by David Blackman and Sebastiano Vigna. It is intended for use in property-based tests that need reproducible pseudorandom sequences.

The generator satisfies the C++ UniformRandomBitGenerator named requirement, so it can be used with standard library distributions and algorithms that accept a URBG.

Usage

Basic Usage

Construct a generator with a seed and call it to produce 64-bit pseudorandom values:

auto const first = rng();
auto const second = rng();
pseudorandom number generator implementing the xoshiro256++ algorithm
Definition prng_xoshiro.hpp:29
::uint64_t uint64_t
A 64-bit unsigned integer type.
Definition cstdint.hpp:47

Use With Standard Distributions

The generator satisfies UniformRandomBitGenerator, so it works with standard library distributions:

auto dist = std::uniform_int_distribution<int>{0, 100};
auto const value = dist(rng);

Use With Arene Base's Distributions

Arene Base also provides its own typed distributions which can be used in a similar way to the standard ones, with some additional features and limitations:

auto const value = dist(rng);
A uniform distribution to apply on top of a bit generator. Primary template (deliberately undefined).
Definition bitwise_uniform_distribution.hpp:19

See Typed Distributions for details on Arene Base's distributions.

Seeding

A single 64-bit seed is expanded into the full 256-bit internal state using the SplitMix64 generator. This ensures the internal state is never all-zero (the only disallowed state) for any seed value.

Different seeds produce different sequences. The same seed always produces the same sequence across all platforms.

Limitations

  • prng_xoshiro is not cryptographically secure. It must not be used for security-sensitive purposes.
  • This PRNG is currently limited to test code only.

References