This class encapsulates a useful, consistent, cross-platform random number generator with multiple utilities. More...
#include <MooseRandom.h>
Public Member Functions | |
void | seed (std::size_t i, unsigned int seed) |
The method seeds one of the independent random number generators. More... | |
Real | rand (std::size_t i) |
This method returns the next random number (Real format) from the specified generator. More... | |
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. More... | |
Real | randNormal (std::size_t i) |
Return next random number drawn from a standard distribution. More... | |
uint32_t | randl (std::size_t i) |
This method returns the next random number (long format) from the specified generator. More... | |
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 supplied range. More... | |
void | saveState () |
This method saves the current state of all generators which can be restored at a later time (i.e. More... | |
void | restoreState () |
This method restores the last saved generator state. More... | |
std::size_t | size () |
Return the number of states. More... | |
Static Public Member Functions | |
static void | seed (unsigned int seed) |
The method seeds the random number generator. More... | |
static Real | rand () |
This method returns the next random number (Real format) from the generator. More... | |
static Real | randNormal (Real mean, Real sigma) |
This method returns the next random number (Real format) from the generator, drawn from a normal distribution centered around mean, with a width of sigma. More... | |
static Real | randNormal () |
Return next random number drawn from a standard distribution. More... | |
static uint32_t | randl () |
This method returns the next random number (long format) from the generator. More... | |
Private Attributes | |
std::unordered_map< std::size_t, std::pair< mt_state, mt_state > > | _states |
We store a pair of states in this map. More... | |
bool | _saved = false |
Flag to make certain that saveState is called prior to restoreState. More... | |
Friends | |
void | dataStore (std::ostream &stream, MooseRandom &v, void *context) |
void | dataLoad (std::istream &stream, MooseRandom &v, void *context) |
This class encapsulates a useful, consistent, cross-platform random number generator with multiple utilities.
Definition at line 36 of file MooseRandom.h.
|
inlinestatic |
This method returns the next random number (Real format) from the generator.
Definition at line 49 of file MooseRandom.h.
Referenced by RandomPartitioner::_do_partition(), RandomICBase::generateRandom(), SymmetricRankTwoTensorTempl< T >::genRandomSymmTensor(), RankTwoTensorTempl< Real >::genRandomSymmTensor(), RankTwoTensorTempl< Real >::genRandomTensor(), Sampler::getRand(), RandomInterface::getRandomReal(), and PropertyReadFile::initVoronoiCenterPoints().
|
inline |
This method returns the next random number (Real format) from the specified generator.
i | the index of the generator |
Definition at line 84 of file MooseRandom.h.
|
inlinestatic |
This method returns the next random number (long format) from the generator.
Definition at line 70 of file MooseRandom.h.
Referenced by Sampler::getRandl(), RandomInterface::getRandomLong(), RandomICBase::RandomICBase(), MooseUtils::resample(), MooseUtils::resampleWithFunctor(), MooseUtils::shuffle(), and RandomData::updateGenerators().
|
inline |
This method returns the next random number (long format) from the specified generator.
i | the index of the generator |
Definition at line 115 of file MooseRandom.h.
|
inline |
This method returns the next random number (long format) from the specified generator within the supplied range.
lower | lower bounds of value |
upper | upper bounds of value |
i | the index of the generator |
Definition at line 130 of file MooseRandom.h.
This method returns the next random number (Real format) from the generator, drawn from a normal distribution centered around mean, with a width of sigma.
mean | center of the random number distribution |
sigma | width of the random number distribution |
Definition at line 59 of file MooseRandom.h.
|
inlinestatic |
Return next random number drawn from a standard distribution.
Definition at line 64 of file MooseRandom.h.
Referenced by randNormal().
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.
i | the index of the generator |
mean | center of the random number distribution |
sigma | width of the random number distribution |
Definition at line 99 of file MooseRandom.h.
|
inline |
Return next random number drawn from a standard distribution.
Definition at line 108 of file MooseRandom.h.
Referenced by randNormal().
|
inline |
This method restores the last saved generator state.
Definition at line 152 of file MooseRandom.h.
Referenced by Sampler::restoreGeneratorState(), and RandomData::updateSeeds().
|
inline |
This method saves the current state of all generators which can be restored at a later time (i.e.
re-generate the same sequence of random numbers of this generator
Definition at line 140 of file MooseRandom.h.
Referenced by Sampler::saveGeneratorState(), and RandomData::updateSeeds().
The method seeds the random number generator.
seed | the seed number |
Definition at line 43 of file MooseRandom.h.
Referenced by Sampler::init(), RankTwoTensorTempl< Real >::initRandom(), SymmetricRankTwoTensorTempl< T >::initRandom(), PropertyReadFile::initVoronoiCenterPoints(), MooseInit::MooseInit(), RandomICBase::RandomICBase(), RandomPartitioner::RandomPartitioner(), seed(), and RandomData::updateGenerators().
The method seeds one of the independent random number generators.
i | the index of the generator |
seed | the seed number |
Definition at line 77 of file MooseRandom.h.
|
inline |
Return the number of states.
Definition at line 164 of file MooseRandom.h.
Referenced by Sampler::advanceGenerators(), Sampler::getRand(), and Sampler::getRandl().
|
friend |
Definition at line 190 of file MooseRandom.h.
|
friend |
Definition at line 184 of file MooseRandom.h.
|
private |
Flag to make certain that saveState is called prior to restoreState.
Definition at line 179 of file MooseRandom.h.
Referenced by restoreState(), and saveState().
|
private |
We store a pair of states in this map.
The first one is the active state, the second is the backup state. It is used to restore state at a later time to the active state.
Definition at line 172 of file MooseRandom.h.
Referenced by dataLoad(), dataStore(), rand(), randl(), randNormal(), restoreState(), saveState(), seed(), and size().