21#include "../pcg-cpp/pcg_random.hpp"
22#include "../IO/ParmParser.H"
67 std::uniform_real_distribution<Real> dist(a,b);
79 std::uniform_int_distribution<IdxType> dist(a,b);
91 std::normal_distribution<Real> dist(mean, stddev);
102 std::poisson_distribution<IdxType> dist(ex);
119 template <
typename T>
121 const std::vector<Real>& w = std::vector<Real>())
const {
122 if (elem.size() == 1)
return elem[0];
123 else if (w.size() == 0)
return elem[
uniformInt(0, elem.size()-1)];
125 std::vector<Real> wCum(w.size());
127 for (
IdxType i = 1; i < w.size(); i++) wCum[i] = wCum[i-1] + w[i];
129 if (x < wCum[0])
return elem[0];
134 if (x < wCum[c])
r = c;
154 template <
typename T>
155 const T&
choose(
const std::vector<T>& elem,
156 const std::vector<Real>& w = std::vector<Real>())
const {
157 if (w.size() == 0)
return elem[
uniformInt(0, elem.size()-1)];
159 std::vector<Real> wCum(w.size());
161 for (
IdxType i = 0; i < w.size(); i++) wCum[i] = wCum[i-1] + w[i];
163 if (x < wCum[0])
return elem[0];
168 if (x < wCum[c])
r = c;
201 void setState(
const std::string& buf);
A class to hold objects where one copy is required per thread.
Basic integer and real types.
Class to parse the criptic input deck.
Definition ParmParser.H:37
Thread-safe random number generator.
Definition RngThread.H:39
ThreadVec< pcg64 * > r
Definition RngThread.H:215
T & choose(std::vector< T > &elem, const std::vector< Real > &w=std::vector< Real >()) const
Randomly choose an element from a vector.
Definition RngThread.H:120
const std::string getState() const
Get a serialized buffer holding the RNG state.
Definition RngThread.cpp:53
static IdxType stateSize()
Return the number of bytes in the RNG state buffer.
Definition RngThread.cpp:83
~RngThread()
Free RngThread object memory.
Definition RngThread.cpp:44
Real uniform(const Real a=0.0, const Real b=1.0) const
Return a random number uniformly-distributed in (a,b)
Definition RngThread.H:66
const T & choose(const std::vector< T > &elem, const std::vector< Real > &w=std::vector< Real >()) const
Randomly choose an element from a const vector.
Definition RngThread.H:155
Real normal(const Real mean=0.0, const Real stddev=1.0) const
Return a normally-distributed random number.
Definition RngThread.H:90
void setState(const std::string &buf)
Restore the RNG state from a buffer.
Definition RngThread.cpp:71
IdxType poisson(const Real ex) const
Return an integer drawn from a Poisson distribution.
Definition RngThread.H:101
IdxType uniformInt(const IdxType a=0, const IdxType b=maxIdx) const
Return a random integer uniformly-distributed in (a,b)
Definition RngThread.H:78
A class to automate private thread copies of objects.
Definition ThreadVec.H:35
IdxType size() const
Return the number of distinct objects stored.
Definition ThreadVec.H:59
The primary namespace for criptic objects.
Definition AdvancePacket.H:25
constexpr IdxType maxIdx
Definition Types.H:55
std::vector< Real >::size_type IdxType
Definition Types.H:45
double Real
Definition Types.H:38