CDT++ 1.0.0
Causal Dynamical Triangulations in C++
Loading...
Searching...
No Matches
cdt::Random Class Referencefinal

A run-owned PCG engine with a recorded seed and stream identifier. More...

#include <Random.hpp>

Collaboration diagram for cdt::Random:

Public Types

using result_type = pcg64::result_type
 Unsigned result type required by std::uniform_random_bit_generator.

Public Member Functions

 Random ()
 Construct a root stream from operating-system entropy.
 Random (RandomSeed const seed, RandomStream const stream=RandomStream{})
 Construct a reproducible PCG stream without consulting entropy.
 Random (std::uint64_t const seed)
 Construct a root stream from a raw seed value.
auto operator() () -> result_type
auto seed () const noexcept -> RandomSeed
auto serialized_state () const -> std::string
 Serialize the complete mutable PCG state for exact continuation.
auto split (RandomStream const stream) const -> Random
 Create a fresh reproducible stream from the same root seed.
auto stream () const noexcept -> RandomStream

Static Public Member Functions

static auto from_serialized_state (RandomSeed const seed, RandomStream const stream, std::string_view const state) -> Random
 Restore an exact PCG continuation point.
static constexpr auto max () noexcept -> result_type
static constexpr auto min () noexcept -> result_type

Detailed Description

A run-owned PCG engine with a recorded seed and stream identifier.

Construct one root engine per simulation. Pass engines by reference to distributions and stochastic algorithms instead of drawing fresh entropy for each sample. split() creates a reproducible, independently parameterized PCG stream for a subsystem or worker.

Random is intentionally not internally synchronized. A mutable instance belongs to one run or one thread. Parallel code must give each worker a distinct stream before drawing from it.

See also
PCG random-number generators

Definition at line 136 of file Random.hpp.

Member Typedef Documentation

◆ result_type

using cdt::Random::result_type = pcg64::result_type

Unsigned result type required by std::uniform_random_bit_generator.

Definition at line 140 of file Random.hpp.

Constructor & Destructor Documentation

◆ Random() [1/3]

cdt::Random::Random ( )
inline

Construct a root stream from operating-system entropy.

Definition at line 158 of file Random.hpp.

References Random().

Referenced by Random(), Random(), from_serialized_state(), and split().

◆ Random() [2/3]

cdt::Random::Random ( std::uint64_t const seed)
inlineexplicit

Construct a root stream from a raw seed value.

Parameters
seedRoot seed recorded for the run.

Definition at line 162 of file Random.hpp.

References Random(), and seed().

◆ Random() [3/3]

cdt::Random::Random ( RandomSeed const seed,
RandomStream const stream = RandomStream{} )
inlineexplicit

Construct a reproducible PCG stream without consulting entropy.

Parameters
seedRoot seed recorded for the run.
streamPCG stream selector; distinct values select distinct sequences for the same root seed.

Definition at line 168 of file Random.hpp.

References seed(), and stream().

Member Function Documentation

◆ from_serialized_state()

auto cdt::Random::from_serialized_state ( RandomSeed const seed,
RandomStream const stream,
std::string_view const state ) -> Random
inlinestaticnodiscard

Restore an exact PCG continuation point.

Parameters
seedRecorded root seed.
streamRecorded stream selector.
stateComplete state produced by serialized_state().
Returns
A generator whose next draw is the saved generator's next draw.
Exceptions
std::invalid_argumentif the state is malformed, contains trailing data, or selects a different PCG stream.

Definition at line 218 of file Random.hpp.

References Random(), seed(), and stream().

Referenced by main().

◆ max()

constexpr auto cdt::Random::max ( ) -> result_type
inlinestaticnodiscardconstexprnoexcept
Returns
The maximum value the engine can generate.

Definition at line 178 of file Random.hpp.

◆ min()

constexpr auto cdt::Random::min ( ) -> result_type
inlinestaticnodiscardconstexprnoexcept
Returns
The minimum value the engine can generate.

Definition at line 174 of file Random.hpp.

◆ operator()()

auto cdt::Random::operator() ( ) -> result_type
inlinenodiscard
Returns
The next value from this engine, advancing its state.

Definition at line 182 of file Random.hpp.

◆ seed()

auto cdt::Random::seed ( ) const -> RandomSeed
inlinenodiscardnoexcept
Returns
The effective root seed for replaying this run.

Definition at line 185 of file Random.hpp.

Referenced by Random(), Random(), and from_serialized_state().

◆ serialized_state()

auto cdt::Random::serialized_state ( ) const -> std::string
inlinenodiscard

Serialize the complete mutable PCG state for exact continuation.

Returns
Locale-independent PCG engine state.

Definition at line 199 of file Random.hpp.

◆ split()

auto cdt::Random::split ( RandomStream const stream) const -> Random
inlinenodiscard

Create a fresh reproducible stream from the same root seed.

Parameters
streamPCG sequence selector for the new engine.
Returns
A new engine at the beginning of the selected sequence.

Definition at line 194 of file Random.hpp.

References Random(), and stream().

◆ stream()

auto cdt::Random::stream ( ) const -> RandomStream
inlinenodiscardnoexcept
Returns
The PCG stream selector used by this engine.

Definition at line 188 of file Random.hpp.

Referenced by Random(), from_serialized_state(), and split().


The documentation for this class was generated from the following file: