CDT++ 1.0.0-rc1
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

Public Member Functions

 Random ()
 Construct a root stream from operating-system entropy.
 Random (Random_seed const seed, Random_stream const stream=0)
 Construct a reproducible PCG stream without consulting entropy.
auto operator() () -> result_type
auto seed () const noexcept -> Random_seed
auto split (Random_stream const stream) const -> Random
 Create a fresh reproducible stream from the same root seed.
auto stream () const noexcept -> Random_stream

Static Public Member Functions

static auto constexpr max () noexcept -> result_type
static auto constexpr min () noexcept -> result_type

Static Private Member Functions

static auto entropy_seed () -> Random_seed

Private Attributes

pcg64 m_engine
Random_seed m_seed {}
Random_stream m_stream {}

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 generatorsPCG random-number generators

Definition at line 42 of file Random.hpp.

Member Typedef Documentation

◆ result_type

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

Definition at line 45 of file Random.hpp.

Constructor & Destructor Documentation

◆ Random() [1/2]

cdt::Random::Random ( )
inline

Construct a root stream from operating-system entropy.

Definition at line 63 of file Random.hpp.

References Random().

Referenced by Random(), and split().

◆ Random() [2/2]

cdt::Random::Random ( Random_seed const seed,
Random_stream const stream = 0 )
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 69 of file Random.hpp.

References seed(), and stream().

Member Function Documentation

◆ entropy_seed()

auto cdt::Random::entropy_seed ( ) -> Random_seed
inlinestaticnodiscardprivate

Definition at line 52 of file Random.hpp.

◆ max()

auto constexpr cdt::Random::max ( ) -> result_type
inlinestaticnodiscardconstexprnoexcept

Definition at line 76 of file Random.hpp.

◆ min()

auto constexpr cdt::Random::min ( ) -> result_type
inlinestaticnodiscardconstexprnoexcept

Definition at line 73 of file Random.hpp.

◆ operator()()

auto cdt::Random::operator() ( ) -> result_type
inlinenodiscard

Definition at line 79 of file Random.hpp.

◆ seed()

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

Definition at line 82 of file Random.hpp.

Referenced by Random().

◆ split()

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

Create a fresh reproducible stream from the same root seed.

Definition at line 89 of file Random.hpp.

References Random(), and stream().

Referenced by main().

◆ stream()

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

Definition at line 85 of file Random.hpp.

Referenced by Random(), and split().

Member Data Documentation

◆ m_engine

pcg64 cdt::Random::m_engine
private

Definition at line 50 of file Random.hpp.

◆ m_seed

Random_seed cdt::Random::m_seed {}
private

Definition at line 48 of file Random.hpp.

◆ m_stream

Random_stream cdt::Random::m_stream {}
private

Definition at line 49 of file Random.hpp.


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