Random number generator. More...
Public Member Functions | |
cachedRandom (const label seed, const label count) | |
Construct given seed and sample count. More... | |
cachedRandom (const cachedRandom &cr, const bool reset=false) | |
Copy constructor with optional reset of sampleI. More... | |
~cachedRandom () | |
label | seed () const |
Return const access to the initial random number seed. More... | |
const scalarList & | samples () const |
Return const access to the list of samples. More... | |
label | sampleI () const |
Return the current sample marker. More... | |
label & | sampleI () |
Return non-const access to the sample marker. More... | |
template<class Type > | |
Type | sample01 () |
Return a sample whose components lie in the range 0-1. More... | |
template<class Type > | |
Type | GaussNormal () |
Return a sample whose components are normally distributed. More... | |
template<class Type > | |
Type | position (const Type &start, const Type &end) |
Return a sample between start and end. More... | |
template<class Type > | |
void | randomise01 (Type &value) |
Randomise value in the range 0-1. More... | |
template<class Type > | |
Type | globalSample01 () |
Return a sample whose components lie in the range 0-1. More... | |
template<class Type > | |
Type | globalGaussNormal () |
Return a sample whose components are normally distributed. More... | |
template<class Type > | |
Type | globalPosition (const Type &start, const Type &end) |
Return a sample between start and end. More... | |
template<class Type > | |
void | globalRandomise01 (Type &value) |
Randomise value in the range 0-1. More... | |
template<> | |
Foam::scalar | sample01 () |
template<> | |
Foam::label | sample01 () |
template<> | |
Foam::scalar | GaussNormal () |
template<> | |
Foam::label | GaussNormal () |
template<> | |
Foam::scalar | position (const scalar &start, const scalar &end) |
template<> | |
Foam::label | position (const label &start, const label &end) |
template<> | |
Foam::scalar | globalSample01 () |
template<> | |
Foam::label | globalSample01 () |
template<> | |
Foam::scalar | globalGaussNormal () |
template<> | |
Foam::label | globalGaussNormal () |
template<> | |
Foam::scalar | globalPosition (const scalar &start, const scalar &end) |
template<> | |
Foam::label | globalPosition (const label &start, const label &end) |
template<> | |
scalar | sample01 () |
template<> | |
label | sample01 () |
template<> | |
scalar | GaussNormal () |
template<> | |
label | GaussNormal () |
template<> | |
scalar | position (const scalar &start, const scalar &end) |
template<> | |
label | position (const label &start, const label &end) |
template<> | |
scalar | globalSample01 () |
template<> | |
label | globalSample01 () |
template<> | |
scalar | globalGaussNormal () |
template<> | |
label | globalGaussNormal () |
template<> | |
scalar | globalPosition (const scalar &start, const scalar &end) |
template<> | |
label | globalPosition (const label &start, const label &end) |
Random number generator.
Pre-computes and caches samples on construction, so that when sample01() is called, the function simply returns the next (pre-computed) sample. On reaching the last sample, the sample sequence is repeated.
Constructed using a seed and sample count. If the supplied count is negative, no caching is performed, and a new sample is generated on each call to sample01().
Note: the copy constructor cannot be used if count = -1.
Definition at line 63 of file cachedRandom.H.
cachedRandom | ( | const label | seed, |
const label | count | ||
) |
Construct given seed and sample count.
Definition at line 56 of file cachedRandom.C.
References forAll, Foam::osRandomDouble(), Foam::osRandomSeed(), cachedRandom::seed(), and List< T >::setSize().
cachedRandom | ( | const cachedRandom & | cr, |
const bool | reset = false |
||
) |
Copy constructor with optional reset of sampleI.
Definition at line 85 of file cachedRandom.C.
References Foam::endl(), Foam::osRandomSeed(), List< T >::size(), and WarningInFunction.
~cachedRandom | ( | ) |
Definition at line 116 of file cachedRandom.C.
|
inline |
Return const access to the initial random number seed.
Definition at line 30 of file cachedRandomI.H.
Referenced by cachedRandom::cachedRandom().
|
inline |
Return const access to the list of samples.
Definition at line 36 of file cachedRandomI.H.
|
inline |
Return the current sample marker.
Definition at line 42 of file cachedRandomI.H.
|
inline |
Return non-const access to the sample marker.
Definition at line 48 of file cachedRandomI.H.
Type sample01 | ( | ) |
Return a sample whose components lie in the range 0-1.
Definition at line 32 of file cachedRandomTemplates.C.
Referenced by Stochastic< CloudType >::calculate(), ConeInjection< CloudType >::ConeInjection(), ConeNozzleInjection< CloudType >::ConeNozzleInjection(), InflationInjection< CloudType >::parcelsToInject(), triangle< Point, PointRef >::randomPoint(), tetrahedron< Point, PointRef >::randomPoint(), exponential::sample(), general::sample(), RosinRammler::sample(), multiNormal::sample(), normal::sample(), ConeNozzleInjection< CloudType >::setPositionAndCell(), ConeInjection< CloudType >::setProperties(), ConeNozzleInjection< CloudType >::setProperties(), StochasticDispersionRAS< CloudType >::update(), SHF< CloudType >::update(), and Stochastic< CloudType >::~Stochastic().
Type GaussNormal | ( | ) |
Return a sample whose components are normally distributed.
with zero mean and unity variance N(0, 1)
Definition at line 45 of file cachedRandomTemplates.C.
Referenced by StochasticDispersionRAS< CloudType >::update(), and GradientDispersionRAS< CloudType >::update().
Type position | ( | const Type & | start, |
const Type & | end | ||
) |
Return a sample between start and end.
Definition at line 58 of file cachedRandomTemplates.C.
Referenced by cachedRandom::GaussNormal(), InflationInjection< CloudType >::parcelsToInject(), uniform::sample(), patchInjectionBase::setPositionAndCell(), ThermoLookupTableInjection< CloudType >::setPositionAndCell(), ReactingLookupTableInjection< CloudType >::setPositionAndCell(), ReactingMultiphaseLookupTableInjection< CloudType >::setPositionAndCell(), KinematicLookupTableInjection< CloudType >::setPositionAndCell(), and ConeInjection< CloudType >::setProperties().
void randomise01 | ( | Type & | value | ) |
Randomise value in the range 0-1.
Definition at line 72 of file cachedRandomTemplates.C.
Type globalSample01 | ( | ) |
Return a sample whose components lie in the range 0-1.
Definition at line 79 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Type globalGaussNormal | ( | ) |
Return a sample whose components are normally distributed.
with zero mean and unity variance N(0, 1)
Definition at line 95 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Type globalPosition | ( | const Type & | start, |
const Type & | end | ||
) |
Return a sample between start and end.
Definition at line 111 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Referenced by cachedRandom::globalGaussNormal(), cachedRandom::globalPosition(), PatchInjection< CloudType >::parcelsToInject(), PatchFlowRateInjection< CloudType >::parcelsToInject(), and patchInjectionBase::setPositionAndCell().
void globalRandomise01 | ( | Type & | value | ) |
Randomise value in the range 0-1.
Definition at line 127 of file cachedRandomTemplates.C.
References UPstream::master(), and Pstream::scatter().
Foam::scalar sample01 | ( | ) |
Definition at line 123 of file cachedRandom.C.
Foam::label sample01 | ( | ) |
Definition at line 130 of file cachedRandom.C.
Foam::scalar GaussNormal | ( | ) |
Definition at line 137 of file cachedRandom.C.
References Foam::log(), Foam::sqr(), and Foam::sqrt().
Foam::label GaussNormal | ( | ) |
Definition at line 165 of file cachedRandom.C.
References cachedRandom::position().
Foam::scalar position | ( | const scalar & | start, |
const scalar & | end | ||
) |
Definition at line 173 of file cachedRandom.C.
Foam::label position | ( | const label & | start, |
const label & | end | ||
) |
Definition at line 183 of file cachedRandom.C.
Foam::scalar globalSample01 | ( | ) |
Definition at line 190 of file cachedRandom.C.
References UPstream::master(), and Pstream::scatter().
Foam::label globalSample01 | ( | ) |
Definition at line 206 of file cachedRandom.C.
References UPstream::master(), and Pstream::scatter().
Foam::scalar globalGaussNormal | ( | ) |
Definition at line 222 of file cachedRandom.C.
References UPstream::master(), and Pstream::scatter().
Foam::label globalGaussNormal | ( | ) |
Definition at line 238 of file cachedRandom.C.
References cachedRandom::globalPosition(), UPstream::master(), and Pstream::scatter().
Foam::scalar globalPosition | ( | const scalar & | start, |
const scalar & | end | ||
) |
Definition at line 255 of file cachedRandom.C.
References cachedRandom::globalPosition(), UPstream::master(), and Pstream::scatter().
Foam::label globalPosition | ( | const label & | start, |
const label & | end | ||
) |
Definition at line 275 of file cachedRandom.C.
References Foam::labelMin, UPstream::master(), and Pstream::scatter().
scalar sample01 | ( | ) |
label sample01 | ( | ) |
scalar GaussNormal | ( | ) |
label GaussNormal | ( | ) |
scalar position | ( | const scalar & | start, |
const scalar & | end | ||
) |
scalar globalSample01 | ( | ) |
label globalSample01 | ( | ) |
scalar globalGaussNormal | ( | ) |
label globalGaussNormal | ( | ) |
scalar globalPosition | ( | const scalar & | start, |
const scalar & | end | ||
) |