pure-cpp 1.0.0
A C++ physics simulation benchmark comparing performance with Python implementations
Rng::Pcg32 Class Reference

A 32-bit Permuted Congruential Generator (pcg32). More...

#include <pcg_random.hpp>

Collaboration diagram for Rng::Pcg32:
Collaboration graph

Public Types

using result_type = uint32_t
 The result type of the generator, required by the UniformRandomBitGenerator concept. More...
 

Public Member Functions

 Pcg32 ()
 Default constructor. Initializes the generator with a default seed. More...
 
 Pcg32 (uint64_t seed)
 Constructs the generator with a specific seed. More...
 
void seed (uint64_t init_seed)
 Seeds the random number generator. More...
 
result_type operator() ()
 Generates the next random number in the sequence. More...
 
void discard (unsigned long long z)
 Discards a specified number of values from the sequence. More...
 

Static Public Member Functions

static constexpr result_type min ()
 Returns the minimum value the generator can produce. More...
 
static constexpr result_type max ()
 Returns the maximum value the generator can produce. More...
 

Private Attributes

uint64_t state_
 The internal state of the generator. More...
 
uint64_t inc_
 The stream selector, which determines the sequence. Must be odd. More...
 

Friends

bool operator== (const Pcg32 &lhs, const Pcg32 &rhs)
 Checks if two generators have the same internal state. More...
 
bool operator!= (const Pcg32 &lhs, const Pcg32 &rhs)
 Checks if two generators have different internal states. More...
 

Detailed Description

A 32-bit Permuted Congruential Generator (pcg32).

This class implements the UniformRandomBitGenerator concept from the C++ standard library, making it compatible with distribution classes like std::uniform_int_distribution and std::uniform_real_distribution.

Definition at line 37 of file pcg_random.hpp.

Member Typedef Documentation

◆ result_type

using Rng::Pcg32::result_type = uint32_t

The result type of the generator, required by the UniformRandomBitGenerator concept.

Definition at line 41 of file pcg_random.hpp.

Constructor & Destructor Documentation

◆ Pcg32() [1/2]

Rng::Pcg32::Pcg32 ( )
inline

Default constructor. Initializes the generator with a default seed.

Definition at line 63 of file pcg_random.hpp.

◆ Pcg32() [2/2]

Rng::Pcg32::Pcg32 ( uint64_t  seed)
inlineexplicit

Constructs the generator with a specific seed.

Parameters
seedThe initial seed value for the generator's state.

Definition at line 69 of file pcg_random.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ discard()

void Rng::Pcg32::discard ( unsigned long long  z)
inline

Discards a specified number of values from the sequence.

Parameters
zThe number of values to discard.

Definition at line 104 of file pcg_random.hpp.

◆ max()

static constexpr result_type Rng::Pcg32::max ( )
inlinestaticconstexpr

Returns the maximum value the generator can produce.

Returns
The maximum value.

Definition at line 55 of file pcg_random.hpp.

◆ min()

static constexpr result_type Rng::Pcg32::min ( )
inlinestaticconstexpr

Returns the minimum value the generator can produce.

Returns
The minimum value (0).

Definition at line 47 of file pcg_random.hpp.

◆ operator()()

result_type Rng::Pcg32::operator() ( )
inline

Generates the next random number in the sequence.

Returns
A 32-bit unsigned random integer.

Definition at line 89 of file pcg_random.hpp.

◆ seed()

void Rng::Pcg32::seed ( uint64_t  init_seed)
inline

Seeds the random number generator.

Parameters
init_seedThe seed value. The stream is also initialised based on this seed.

Definition at line 77 of file pcg_random.hpp.

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const Pcg32 lhs,
const Pcg32 rhs 
)
friend

Checks if two generators have different internal states.

Returns
True if the state or stream are different.

Definition at line 122 of file pcg_random.hpp.

◆ operator==

bool operator== ( const Pcg32 lhs,
const Pcg32 rhs 
)
friend

Checks if two generators have the same internal state.

Returns
True if the state and stream are identical.

Definition at line 115 of file pcg_random.hpp.

Member Data Documentation

◆ inc_

uint64_t Rng::Pcg32::inc_
private

The stream selector, which determines the sequence. Must be odd.

Definition at line 133 of file pcg_random.hpp.

◆ state_

uint64_t Rng::Pcg32::state_
private

The internal state of the generator.

Definition at line 128 of file pcg_random.hpp.


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