Public Member Functions | Private Member Functions | Private Attributes
cachedRandom Class Reference

Random number generator. More...

Collaboration diagram for cachedRandom:
Collaboration graph
[legend]

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::scalar 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::scalar 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)
 

Private Member Functions

scalar scalar01 ()
 Returns the current sample. More...
 

Private Attributes

label seed_
 Initial random number seed. More...
 
scalarList samples_
 List of scalar samples. More...
 
label sampleI_
 Current sample marker. More...
 
bool hasGaussSample_
 Indicator, which tells if there is a stored gaussian sample. More...
 
scalar gaussSample_
 Stored sample value. More...
 

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::sampleI_, cachedRandom::samples_, cachedRandom::seed(), cachedRandom::seed_, and List::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(), cachedRandom::gaussSample_, cachedRandom::hasGaussSample_, Foam::osRandomSeed(), cachedRandom::sampleI_, cachedRandom::samples_, cachedRandom::seed_, List::size(), and WarningInFunction.

Here is the call graph for this function:

◆ ~cachedRandom()

Definition at line 116 of file cachedRandom.C.

Member Function Documentation

◆ scalar01()

Foam::scalar scalar01 ( )
private

Returns the current sample.

Definition at line 32 of file cachedRandom.C.

References Foam::osRandomDouble(), s(), cachedRandom::sampleI_, cachedRandom::samples_, and List::size().

Referenced by edgeIntersections::inlinePerturb(), main(), edgeIntersections::offsetPerturb(), tetrahedron::randomPoint(), and cachedRandom::sample01().

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

◆ seed()

Foam::label seed ( ) const
inline

Return const access to the initial random number seed.

Definition at line 30 of file cachedRandomI.H.

References cachedRandom::seed_.

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]

label& sampleI ( )
inline

Return non-const access to the sample marker.

◆ sample01() [1/4]

Type sample01

◆ GaussNormal() [1/4]

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

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/4]

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/4]

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 PatchInjection< CloudType >::parcelsToInject().

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/4]

Foam::label sample01 ( )

Definition at line 123 of file cachedRandom.C.

◆ GaussNormal() [2/4]

Foam::label 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:

◆ 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/4]

Foam::label globalSample01 ( )

Definition at line 190 of file cachedRandom.C.

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

Here is the call graph for this function:

◆ globalGaussNormal() [2/4]

Foam::label globalGaussNormal ( )

Definition at line 222 of file cachedRandom.C.

References 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 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() [3/4]

scalar sample01 ( )

◆ sample01() [4/4]

label sample01 ( )

◆ GaussNormal() [3/4]

scalar GaussNormal ( )

◆ GaussNormal() [4/4]

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() [3/4]

scalar globalSample01 ( )

◆ globalSample01() [4/4]

label globalSample01 ( )

◆ globalGaussNormal() [3/4]

scalar globalGaussNormal ( )

◆ globalGaussNormal() [4/4]

label globalGaussNormal ( )

◆ globalPosition() [4/5]

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

◆ globalPosition() [5/5]

label globalPosition ( const label start,
const label end 
)

Field Documentation

◆ seed_

label seed_
private

Initial random number seed.

Definition at line 68 of file cachedRandom.H.

Referenced by cachedRandom::cachedRandom(), and cachedRandom::seed().

◆ samples_

scalarList samples_
private

List of scalar samples.

Definition at line 71 of file cachedRandom.H.

Referenced by cachedRandom::cachedRandom(), and cachedRandom::scalar01().

◆ sampleI_

label sampleI_
private

Current sample marker.

Definition at line 74 of file cachedRandom.H.

Referenced by cachedRandom::cachedRandom(), and cachedRandom::scalar01().

◆ hasGaussSample_

bool hasGaussSample_
private

Indicator, which tells if there is a stored gaussian sample.

Definition at line 77 of file cachedRandom.H.

Referenced by cachedRandom::cachedRandom().

◆ gaussSample_

scalar gaussSample_
private

Stored sample value.

Definition at line 80 of file cachedRandom.H.

Referenced by cachedRandom::cachedRandom().


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