dasmig-core 1.2.0
Shared random engine, distributions and data tiers for the dasmig generator libraries
Loading...
Searching...
No Matches
rng.hpp File Reference

The random engine every generator library uses: xoshiro256** seeded through SplitMix64, with labelled child streams. More...

#include <array>
#include <bit>
#include <cstdint>
#include <limits>
#include <random>
#include <string_view>

Go to the source code of this file.

Classes

class  dasmig::core::splitmix64
 The SplitMix64 generator (Steele, Lea and Flood 2014). More...
 
class  dasmig::core::rng
 The core random engine: xoshiro256** (Blackman and Vigna 2018). More...
 

Functions

constexpr std::uint64_t dasmig::core::splitmix64_mix (std::uint64_t z) noexcept
 The SplitMix64 output function (a bijection on 64-bit values).
 
constexpr std::uint64_t dasmig::core::fnv1a64 (std::string_view text) noexcept
 64-bit FNV-1a hash of the bytes of a string.
 
constexpr std::uint64_t dasmig::core::hash_combine (std::uint64_t hash, std::uint64_t value) noexcept
 Combine a hash with another 64-bit value, order-sensitively.
 

Detailed Description

The random engine every generator library uses: xoshiro256** seeded through SplitMix64, with labelled child streams.

Author
Diego Dasso Migotto (diegomigotto at hotmail dot com)

The algorithms are fixed and the output is part of the core's contract: a seed gives the same sequence on every compiler and platform. Changing any of them is a major version change.

Definition in file rng.hpp.

Function Documentation

◆ fnv1a64()

constexpr std::uint64_t dasmig::core::fnv1a64 ( std::string_view  text)
constexprnoexcept

64-bit FNV-1a hash of the bytes of a string.

Labels are hashed as bytes, so pass UTF-8: a std::wstring label would hash differently on Windows (UTF-16) and elsewhere (UTF-32).

Parameters
textBytes to hash.
Returns
The hash.

Definition at line 66 of file rng.hpp.

◆ hash_combine()

constexpr std::uint64_t dasmig::core::hash_combine ( std::uint64_t  hash,
std::uint64_t  value 
)
constexprnoexcept

Combine a hash with another 64-bit value, order-sensitively.

splitmix64_mix(hash ^ splitmix64_mix(value)), the same construction as rng::child_seed().

Parameters
hashRunning hash.
valueValue to fold in.
Returns
The combined hash.

Definition at line 85 of file rng.hpp.

◆ splitmix64_mix()

constexpr std::uint64_t dasmig::core::splitmix64_mix ( std::uint64_t  z)
constexprnoexcept

The SplitMix64 output function (a bijection on 64-bit values).

Parameters
zInput value.
Returns
The mixed value.

Definition at line 29 of file rng.hpp.