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