TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
triqs::mc_tools::random_generator

#include <triqs/mc_tools/random_generator.hpp>

Detailed Description

Random number generator with a selectable underlying engine.

The following engine names are currently accepted by the constructor:

  • empty string – a built-in custom Mersenne Twister RNG
  • mt19937
  • mt11213b
  • lagged_fibonacci607
  • lagged_fibonacci1279
  • lagged_fibonacci2281
  • lagged_fibonacci3217
  • lagged_fibonacci4423
  • lagged_fibonacci9689
  • lagged_fibonacci19937
  • lagged_fibonacci23209
  • lagged_fibonacci44497
  • ranlux3

For non-empty names, the underlying engine is provided by boost.random.

For performance reasons, we use a buffer for the generated random numbers to avoid some of the costs of repeated function calls to the RNG.

Definition at line 71 of file random_generator.hpp.

Public Member Functions

 random_generator ()
 Default constructor uses the mt19937 engine with the default seed.
 random_generator (random_generator &&)=default
 Default move constructor.
 random_generator (random_generator const &)=delete
 Deleted copy constructor.
 random_generator (std::string name, std::uint32_t seed, std::size_t buffer_size=1000)
 Construct a random generator by wrapping the specified RNG and seeding it with the given seed.
std::string name () const
 Get the name of the underlying RNG.
double operator() ()
 Generate a random sample from the uniform distribution defined on the interval \( [0, 1) \).
double operator() (double a, double b)
 Generate a random sample from the uniform distribution defined on the interval \( [a, b) \).
double operator() (double b)
 Generate a random sample from the uniform distribution defined on the interval \( [0, b) \).
template<typename T>
requires (std::integral<T>)
operator() (T i)
 Generate a random sample from the uniform integer distribution defined on \( \{0, ..., i-1 \}\).
random_generatoroperator= (random_generator &&)=default
 Default move assignment operator.
double preview ()
 Look ahead at the next value that will be generated when the generator is called.

Static Public Member Functions

static std::string hdf5_format ()
 Get the HDF5 format tag.

Static Public Attributes

static constexpr std::uint32_t default_seed = 198
 Default seed for the underlying RNG.

Friends

void h5_read (h5::group g, std::string const &name, random_generator &rng)
 Read the RNG object from HDF5.
void h5_write (h5::group g, std::string const &name, random_generator const &rng)
 Write the RNG object to HDF5.

Constructor & Destructor Documentation

◆ random_generator()

triqs::mc_tools::random_generator::random_generator ( std::string name,
std::uint32_t seed,
std::size_t buffer_size = 1000 )

Construct a random generator by wrapping the specified RNG and seeding it with the given seed.

The given name has to correspond to one of the supported engines. If the name does not match any of the supported engines, a runtime error is raised.

An empty name selects the built-in custom Mersenne Twister RNG.

Parameters
nameName of the RNG to be used.
seedSeed for the RNG.
buffer_sizeSize of the buffer used to store random numbers.

Definition at line 51 of file random_generator.cpp.

Member Function Documentation

◆ operator()() [1/4]

double triqs::mc_tools::random_generator::operator() ( )
inline

Generate a random sample from the uniform distribution defined on the interval \( [0, 1) \).

Returns
Uniform random double from the interval \( [0, 1) \).

Definition at line 159 of file random_generator.hpp.

◆ operator()() [2/4]

double triqs::mc_tools::random_generator::operator() ( double a,
double b )
inline

Generate a random sample from the uniform distribution defined on the interval \( [a, b) \).

Parameters
aLower bound of the interval.
bUpper bound of the interval.
Returns
Uniform random double from the interval \( [a, b) \).

Definition at line 178 of file random_generator.hpp.

◆ operator()() [3/4]

double triqs::mc_tools::random_generator::operator() ( double b)
inline

Generate a random sample from the uniform distribution defined on the interval \( [0, b) \).

Parameters
bUpper bound of the interval.
Returns
Uniform random double from the interval \( [0, b) \).

Definition at line 169 of file random_generator.hpp.

◆ operator()() [4/4]

template<typename T>
requires (std::integral<T>)
T triqs::mc_tools::random_generator::operator() ( T i)
inline

Generate a random sample from the uniform integer distribution defined on \( \{0, ..., i-1 \}\).

Template Parameters
TIntegral type.
Parameters
iUpper bound (excluded).
Returns
Uniform random integer.

Definition at line 142 of file random_generator.hpp.

◆ preview()

double triqs::mc_tools::random_generator::preview ( )
inlinenodiscard

Look ahead at the next value that will be generated when the generator is called.

Returns
Uniform random double from the interval \( [0, 1) \).

Definition at line 150 of file random_generator.hpp.

◆ h5_read

void h5_read ( h5::group g,
std::string const & name,
random_generator & rng )
friend

Read the RNG object from HDF5.

Parameters
gh5::group to be read from.
nameName of the dataset/subgroup.
rngRNG object to be read into.

Definition at line 211 of file random_generator.hpp.

◆ h5_write

void h5_write ( h5::group g,
std::string const & name,
random_generator const & rng )
friend

Write the RNG object to HDF5.

Parameters
gh5::group to be written to.
nameName of the dataset/subgroup.
rngRNG object to be written.

Definition at line 193 of file random_generator.hpp.


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