17 #include "randistrs.h" 20 #include <unordered_map> 143 unsigned int randl(std::size_t n,
unsigned int lower,
unsigned int upper)
const 145 mooseAssert(upper >= lower,
"randl: upper < lower");
146 const auto range = upper - lower;
149 range, [&range](mt_state * state) {
return rds_iuniform(state, 0, range); },
_seed);
154 return lower + it->second.evaluate(n);
181 template <
typename T>
191 Generator(std::function<T(mt_state *)> rng_func,
unsigned int seed)
240 void advance(mt_state & state, std::size_t count)
242 for (std::size_t i = 0; i < count; ++i)
290 dataStore(std::ostream & stream, std::unique_ptr<MooseRandomStateless> & v,
void * context)
292 unsigned int seed = v->getSeed();
299 dataLoad(std::istream & stream, std::unique_ptr<MooseRandomStateless> & v,
void * context)
303 v = std::make_unique<MooseRandomStateless>(seed);
Generator< Real > _rand_generator
Uniform Real [0, 1)
const std::function< T(mt_state *)> _rng_func
RNG function pointer.
void dataLoad(std::istream &stream, MooseRandomStateless &v, void *context)
void advance(std::size_t count)
Advance the internal RNG state by a fixed count.
std::size_t _advance_count
The number of counts the generators have advanced This needs to be kept around for generation of new ...
unsigned int getSeed() const
Get the seed value used to initialize this handler's RNGs.
unsigned int randl(std::size_t n, unsigned int lower, unsigned int upper) const
Return the n-th bounded integer random number in [lower, upper).
MooseRandomStateless & operator=(const MooseRandomStateless &)=delete
Generator< unsigned int > _randl_generator
Uniform uint32.
const unsigned int _seed
Seed shared by all internal generators.
void storeHelper(std::ostream &stream, P &data, void *context)
Scalar helper routine.
Real rand(std::size_t n) const
Return the n-th uniform Real random number in [0, 1).
void advance(mt_state &state, std::size_t count)
Advance a given RNG state count times.
std::size_t _current_index
Index of next number to be generated.
MooseRandomStateless(const MooseRandomStateless &)=delete
Deleted copy constructor and assignment to prevent deep-copy of mutable state.
unsigned int randl(std::size_t n) const
Return the n-th unsigned integer from the full 32-bit uniform range.
Template class wrapping a single random number generator function.
std::size_t getAdvanceCount() const
Get the amount that the RNGs have advanced by advance(count) calls.
T evaluate(std::size_t n) const
Evaluate the n-th random number in the sequence.
mt_state _current_state
Cached working RNG state.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void advance(std::size_t count)
Advance all generators by the specified number.
void dataStore(std::ostream &stream, MooseRandomStateless &v, void *context)
A deterministic, indexable random number generator built on top of the randistrs library.
Generator(std::function< T(mt_state *)> rng_func, unsigned int seed)
Construct a new Generator with a function and seed.
mt_state _initial_state
Base RNG state (seeded)
std::unordered_map< unsigned int, Generator< unsigned int > > _randlb_generators
Bounded uniform uint32 (indexed based on bounding range)
MooseRandomStateless(unsigned int seed)
Construct a new MooseRandomStateless with a given seed.
void loadHelper(std::istream &stream, P &data, void *context)
Scalar helper routine.