gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
Gambit::Utils::specialised_threadsafe_rng< Engine > Class Template Reference

Derived thread-safe random number generator class, templated on the RNG engine type. More...

#include <threadsafe_rng.hpp>

Inheritance diagram for Gambit::Utils::specialised_threadsafe_rng< Engine >:
Collaboration diagram for Gambit::Utils::specialised_threadsafe_rng< Engine >:

Public Member Functions

 specialised_threadsafe_rng (int &seed)
 Create RNG engines, one for each thread. More...
 
virtual ~specialised_threadsafe_rng ()
 Destroy RNG engines. More...
 
virtual result_type operator() ()
 Generate a random integer using the chosen engine Selected uniformly from range (min,max). More...
 
- Public Member Functions inherited from Gambit::Utils::threadsafe_rng
virtual ~threadsafe_rng ()=0
 Pure virtual destructor to force overriding in derived class. More...
 

Private Attributes

std::independent_bits_engine< Engine, 64, result_type > * rngs
 Pointer to array of RNGs, one each for each thread. More...
 

Additional Inherited Members

- Public Types inherited from Gambit::Utils::threadsafe_rng
typedef std::uint64_t result_type
 Return type (will convert underlying RNG type to this) More...
 
- Static Public Member Functions inherited from Gambit::Utils::threadsafe_rng
static constexpr result_type min ()
 Operators for compliance with RandomNumberEngine interface -> random distribution sampling. More...
 
static constexpr result_type max ()
 

Detailed Description

template<typename Engine>
class Gambit::Utils::specialised_threadsafe_rng< Engine >

Derived thread-safe random number generator class, templated on the RNG engine type.

Definition at line 91 of file threadsafe_rng.hpp.

Constructor & Destructor Documentation

◆ specialised_threadsafe_rng()

template<typename Engine>
Gambit::Utils::specialised_threadsafe_rng< Engine >::specialised_threadsafe_rng ( int seed)
inline

Create RNG engines, one for each thread.

Definition at line 95 of file threadsafe_rng.hpp.

References combine_hdf5::index.

96  {
97  const int max_threads = omp_get_max_threads();
98  rngs = new std::independent_bits_engine<Engine,64,result_type>[max_threads];
99  if (seed == -1) seed = std::random_device()();
100  for(int index = 0; index < max_threads; ++index)
101  {
102  rngs[index] = std::independent_bits_engine<Engine,64,result_type>(index + seed);
103  }
104  }
std::independent_bits_engine< Engine, 64, result_type > * rngs
Pointer to array of RNGs, one each for each thread.

◆ ~specialised_threadsafe_rng()

template<typename Engine>
virtual Gambit::Utils::specialised_threadsafe_rng< Engine >::~specialised_threadsafe_rng ( )
inlinevirtual

Destroy RNG engines.

Definition at line 107 of file threadsafe_rng.hpp.

107 { delete [] rngs; }
std::independent_bits_engine< Engine, 64, result_type > * rngs
Pointer to array of RNGs, one each for each thread.

Member Function Documentation

◆ operator()()

template<typename Engine>
virtual result_type Gambit::Utils::specialised_threadsafe_rng< Engine >::operator() ( )
inlinevirtual

Generate a random integer using the chosen engine Selected uniformly from range (min,max).

To be used as an entropy source for stdlib distributions. If you want (0,1) random doubles then please use Random::draw(), NOT this function!

Implements Gambit::Utils::threadsafe_rng.

Definition at line 113 of file threadsafe_rng.hpp.

114  {
115  return rngs[omp_get_thread_num()]();
116  }
std::independent_bits_engine< Engine, 64, result_type > * rngs
Pointer to array of RNGs, one each for each thread.

Member Data Documentation

◆ rngs

template<typename Engine>
std::independent_bits_engine<Engine,64,result_type>* Gambit::Utils::specialised_threadsafe_rng< Engine >::rngs
private

Pointer to array of RNGs, one each for each thread.

Definition at line 121 of file threadsafe_rng.hpp.


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