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

Here is the call graph for this function:

Definition at line 118 of file cachedRandom.C.

Member Function Documentation

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:

const Foam::scalarList & samples ( ) const
inline

Return const access to the list of samples.

Definition at line 36 of file cachedRandomI.H.

Foam::label sampleI ( ) const
inline

Return the current sample marker.

Definition at line 42 of file cachedRandomI.H.

Foam::label & sampleI ( )
inline

Return non-const access to the sample marker.

Definition at line 48 of file cachedRandomI.H.

Type sample01 ( )
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:

Type position ( const Type &  start,
const Type &  end 
)
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().

Here is the call graph for this function:

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:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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:

Foam::scalar sample01 ( )

Definition at line 125 of file cachedRandom.C.

Foam::label sample01 ( )

Definition at line 132 of file cachedRandom.C.

Foam::scalar GaussNormal ( )

Definition at line 139 of file cachedRandom.C.

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

Here is the call graph for this function:

Foam::label GaussNormal ( )

Definition at line 167 of file cachedRandom.C.

References cachedRandom::position().

Here is the call graph for this function:

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

Definition at line 175 of file cachedRandom.C.

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

Definition at line 185 of file cachedRandom.C.

Foam::scalar globalSample01 ( )

Definition at line 192 of file cachedRandom.C.

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

Here is the call graph for this function:

Foam::label globalSample01 ( )

Definition at line 208 of file cachedRandom.C.

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

Here is the call graph for this function:

Foam::scalar globalGaussNormal ( )

Definition at line 224 of file cachedRandom.C.

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

Here is the call graph for this function:

Foam::label globalGaussNormal ( )

Definition at line 240 of file cachedRandom.C.

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

Here is the call graph for this function:

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

Definition at line 257 of file cachedRandom.C.

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

Here is the call graph for this function:

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

Definition at line 277 of file cachedRandom.C.

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

Here is the call graph for this function:

scalar sample01 ( )
label sample01 ( )
scalar GaussNormal ( )
label GaussNormal ( )
scalar position ( const scalar &  start,
const scalar &  end 
)
label position ( const label start,
const label end 
)
scalar globalSample01 ( )
label globalSample01 ( )
scalar globalGaussNormal ( )
label globalGaussNormal ( )
scalar globalPosition ( const scalar &  start,
const scalar &  end 
)
label globalPosition ( const label start,
const label end 
)

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