16 #include <unordered_map> 19 #include "randistrs.h" 50 static inline Real rand() {
return mt_ldrand(); }
60 static inline Real randNormal(Real mean, Real sigma) {
return rd_normal(mean, sigma); }
71 static inline uint32_t
randl() {
return mt_lrand(); }
88 return mts_ldrand(&(
_states[i].first));
102 mooseAssert(
_states.find(i) !=
_states.end(),
"No random state initialized for id: " << i);
103 return rds_normal(&(
_states[i].first), mean, sigma);
116 inline uint32_t
randl(std::size_t i)
118 mooseAssert(
_states.find(i) !=
_states.end(),
"No random state initialized for id: " << i);
119 return mts_lrand(&(
_states[i].first));
131 inline uint32_t
randl(std::size_t i, uint32_t lower, uint32_t upper)
133 mooseAssert(
_states.find(i) !=
_states.end(),
"No random state initialized for id: " << i);
134 return rds_iuniform(&(
_states[i].first), lower, upper);
146 [](std::pair<const std::size_t, std::pair<mt_state, mt_state>> & pair)
147 { pair.second.second = pair.second.first; });
155 mooseAssert(
_saved,
"saveState() must be called prior to restoreState().");
158 [](std::pair<const std::size_t, std::pair<mt_state, mt_state>> & pair)
159 { pair.second.first = pair.second.second; });
173 std::unordered_map<std::size_t, std::pair<mt_state, mt_state>>
_states;
176 friend void dataStore<MooseRandom>(std::ostream & stream,
MooseRandom & v,
void * context);
177 friend void dataLoad<MooseRandom>(std::istream & stream,
MooseRandom & v,
void * context);
std::unordered_map< std::size_t, std::pair< mt_state, mt_state > > _states
We store a pair of states in this map.
static uint32_t randl()
This method returns the next random number (long format) from the generator.
void dataStore(std::ostream &stream, MooseRandom &v, void *context)
bool _saved
Flag to make certain that saveState is called prior to restoreState.
void saveState()
This method saves the current state of all generators which can be restored at a later time (i...
static Real randNormal()
Return next random number drawn from a standard distribution.
void seed(std::size_t i, unsigned int seed)
The method seeds one of the independent random number generators.
void dataLoad(std::istream &stream, MooseRandom &v, void *context)
Real randNormal(std::size_t i, Real mean, Real sigma)
This method returns the next random number (Real format) from the specified generator, drawn from a normal distribution centered around mean, with a width of sigma.
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
uint32_t randl(std::size_t i)
This method returns the next random number (long format) from the specified generator.
void restoreState()
This method restores the last saved generator state.
std::size_t size()
Return the number of states.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static void seed(unsigned int seed)
The method seeds the random number generator.
static Real rand()
This method returns the next random number (Real format) from the generator.
Real randNormal(std::size_t i)
Return next random number drawn from a standard distribution.
Real rand(std::size_t i)
This method returns the next random number (Real format) from the specified generator.
static Real randNormal(Real mean, Real sigma)
This method returns the next random number (Real format) from the generator, drawn from a normal dist...
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.
uint32_t randl(std::size_t i, uint32_t lower, uint32_t upper)
This method returns the next random number (long format) from the specified generator within the supp...
This class encapsulates a useful, consistent, cross-platform random number generator with multiple ut...