Public Member Functions | List of all members
cachedRandom Class Reference

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 scalarListsamples () const
 Return const access to the list of samples. More...
 
label sampleI () const
 Return the current sample marker. More...
 
labelsampleI ()
 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)
 

Detailed Description

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.

Source files

Definition at line 63 of file cachedRandom.H.

Constructor & Destructor Documentation

◆ cachedRandom() [1/2]

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().

Here is the call graph for this function:

◆ cachedRandom() [2/2]

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.

Here is the call graph for this function:

◆ ~cachedRandom()

Definition at line 116 of file cachedRandom.C.

Member Function Documentation

◆ seed()

Foam::label seed ( ) const
inline

Return const access to the initial random number seed.

Definition at line 30 of file cachedRandomI.H.

Referenced by cachedRandom::cachedRandom().

Here is the caller graph for this function:

◆ samples()

const Foam::scalarList & samples ( ) const
inline

Return const access to the list of samples.

Definition at line 36 of file cachedRandomI.H.

◆ sampleI() [1/2]

Foam::label sampleI ( ) const
inline

Return the current sample marker.

Definition at line 42 of file cachedRandomI.H.

◆ sampleI() [2/2]

Foam::label & sampleI ( )
inline

Return non-const access to the sample marker.

Definition at line 48 of file cachedRandomI.H.

◆ sample01() [1/5]

Type sample01 ( )

◆ GaussNormal() [1/5]

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 BrownianMotionForce< CloudType >::calcCoupled(), StochasticDispersionRAS< CloudType >::update(), and GradientDispersionRAS< CloudType >::update().

Here is the caller graph for this function:

◆ position() [1/5]

Type position ( const Type &  start,
const Type &  end 
)

◆ randomise01()

void randomise01 ( Type &  value)

Randomise value in the range 0-1.

Definition at line 72 of file cachedRandomTemplates.C.

◆ globalSample01() [1/5]

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().

Here is the call graph for this function:

◆ globalGaussNormal() [1/5]

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().

Here is the call graph for this function:

◆ globalPosition() [1/5]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalRandomise01()

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().

Here is the call graph for this function:

◆ sample01() [2/5]

Foam::scalar sample01 ( )

Definition at line 123 of file cachedRandom.C.

◆ sample01() [3/5]

Foam::label sample01 ( )

Definition at line 130 of file cachedRandom.C.

◆ GaussNormal() [2/5]

Foam::scalar GaussNormal ( )

Definition at line 137 of file cachedRandom.C.

References Foam::log(), Foam::sqr(), and Foam::sqrt().

Here is the call graph for this function:

◆ GaussNormal() [3/5]

Foam::label GaussNormal ( )

Definition at line 165 of file cachedRandom.C.

References cachedRandom::position().

Here is the call graph for this function:

◆ position() [2/5]

Foam::scalar position ( const scalar &  start,
const scalar &  end 
)

Definition at line 173 of file cachedRandom.C.

◆ position() [3/5]

Foam::label position ( const label start,
const label end 
)

Definition at line 183 of file cachedRandom.C.

◆ globalSample01() [2/5]

Foam::scalar globalSample01 ( )

Definition at line 190 of file cachedRandom.C.

References UPstream::master(), and Pstream::scatter().

Here is the call graph for this function:

◆ globalSample01() [3/5]

Foam::label globalSample01 ( )

Definition at line 206 of file cachedRandom.C.

References UPstream::master(), and Pstream::scatter().

Here is the call graph for this function:

◆ globalGaussNormal() [2/5]

Foam::scalar globalGaussNormal ( )

Definition at line 222 of file cachedRandom.C.

References UPstream::master(), and Pstream::scatter().

Here is the call graph for this function:

◆ globalGaussNormal() [3/5]

Foam::label globalGaussNormal ( )

Definition at line 238 of file cachedRandom.C.

References cachedRandom::globalPosition(), UPstream::master(), and Pstream::scatter().

Here is the call graph for this function:

◆ globalPosition() [2/5]

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().

Here is the call graph for this function:

◆ globalPosition() [3/5]

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().

Here is the call graph for this function:

◆ sample01() [4/5]

scalar sample01 ( )

◆ sample01() [5/5]

label sample01 ( )

◆ GaussNormal() [4/5]

scalar GaussNormal ( )

◆ GaussNormal() [5/5]

label GaussNormal ( )

◆ position() [4/5]

scalar position ( const scalar &  start,
const scalar &  end 
)

◆ position() [5/5]

label position ( const label start,
const label end 
)

◆ globalSample01() [4/5]

scalar globalSample01 ( )

◆ globalSample01() [5/5]

label globalSample01 ( )

◆ globalGaussNormal() [4/5]

scalar globalGaussNormal ( )

◆ globalGaussNormal() [5/5]

label globalGaussNormal ( )

◆ globalPosition() [4/5]

scalar globalPosition ( const scalar &  start,
const scalar &  end 
)

◆ globalPosition() [5/5]

label globalPosition ( const label start,
const label end 
)

The documentation for this class was generated from the following files: