25 #include <trng/discrete_dist.hpp> 26 #include <trng/lcg64.hpp> 27 #include <trng/uniform01_dist.hpp> 28 #include <trng/uniform_int_dist.hpp> 32 #include <pcg/pcg_random.hpp> 33 #include <randutils/randutils.hpp> 50 class RnEngine :
public Rn<pcg64>
64 RnMan::RnMan() : m_rn(make_shared<RnEngine>()) {}
76 return m_rn->GetUniformIntGenerator(a, b, i);
81 return m_rn->GetDiscreteGenerator(weights.begin(), weights.end(), i);
86 array<double, 2> weights{ 1.0 - fraction, fraction};
89 auto dist =
m_rn->GetDiscreteGenerator(weights.begin(), weights.end(), i);
90 return static_cast<bool>(dist());
97 void RnMan::Shuffle(vector<unsigned int>& indices,
unsigned int i) {
return m_rn->Shuffle(indices, i); }
bool IsEmpty() const
Is this een empty (i.e. non-initialized Rn)?
std::function< int()> GetDiscreteGenerator(const std::vector< double > &weights, unsigned int i=0U)
Return generator for ints [0, n-1[ with non-negative weights p_j (i=0,..,n-1) using i-th random strea...
Rn()
Default constructor build empty manager.
void Initialize(const RnInfo &info)
Initalize with data in Info.
std::function< int()> GetUniformIntGenerator(int a, int b, unsigned int i=0U)
Return a generator for uniform ints in [a, b[ (a < b) using i-th random stream.
void Shuffle(std::vector< unsigned int > &indices, unsigned int i)
Random shuffle of vector of int indices using i-th random stream.
RnMan()
Default constructor builds empty (uninitialized) manager.
bool operator==(const RnMan &other)
Equality of states.
std::function< double()> GetUniform01Generator(unsigned int i=0U)
Return a generator for uniform doubles in [0, 1[ using i-th random stream.
RnInfo GetInfo() const
Return the state of the random engines.
bool MakeWeightedCoinFlip(double fraction, unsigned int i=0U)
Make weighted coin flip: <fraction> of the flips need to come up true.
Miscellaneous string utilities.
Namespace for the simulator and related classes.
Information on random number management state.
std::shared_ptr< RnEngine > m_rn