Random Class Reference

Random number generator. More...

Public Member Functions

 Random (const label s)
 Construct from a seed. More...
 
 ~Random ()
 Destructor. More...
 
scalar scalar01 ()
 Advance the state and return a scalar sample from a uniform. More...
 
scalar scalarAB (const scalar a, const scalar b)
 Advance the state and return a scalar sample from a uniform. More...
 
scalar scalarNormal ()
 Advance the state and return a scalar sample from a normal. More...
 
template<class Type >
Type sample01 ()
 Advance the state and return a sample of a given type from a. More...
 
template<class Type >
Type sampleAB (const Type &a, const Type &b)
 Advance the state and return a sample of a given type from a. More...
 
template<class Type >
Type sampleNormal ()
 Advance the state and return a sample of a given type from a. More...
 
scalar globalScalar01 ()
 Advance the state and return a scalar sample from a uniform. More...
 
template<class Container >
void permute (Container &l)
 Randomly permute a list. More...
 
template<>
scalar sample01 ()
 
template<>
scalar sampleAB (const scalar &a, const scalar &b)
 
template<>
label sampleAB (const label &a, const label &b)
 
template<>
scalar sampleNormal ()
 

Detailed Description

Random number generator.

This is a clone of the drand48 algorithm. This is significantly quicker than drand48, presumably due to the compiler inlining the sampling methods. It is also significantly quicker than the standard library linear congruential engine, as it does not use Schrage's algorithm to prevent overflow.

See http://pubs.opengroup.org/onlinepubs/007908775/xsh/drand48.html for details of the seeding and iteration sequence.

Source files

Definition at line 57 of file Random.H.

Constructor & Destructor Documentation

◆ Random()

Random ( const label  s)
inline

Construct from a seed.

Definition at line 40 of file RandomI.H.

◆ ~Random()

~Random ( )
inline

Destructor.

Definition at line 50 of file RandomI.H.

Member Function Documentation

◆ scalar01()

◆ scalarAB()

Foam::scalar scalarAB ( const scalar  a,
const scalar  b 
)
inline

Advance the state and return a scalar sample from a uniform.

distribution between two limits

Definition at line 62 of file RandomI.H.

References b.

◆ scalarNormal()

Foam::scalar scalarNormal ( )

Advance the state and return a scalar sample from a normal.

distribution with mean zero and standard deviation one

Definition at line 31 of file Random.C.

References f(), Foam::log(), Random::scalar01(), Foam::sqr(), and Foam::sqrt().

Referenced by BrownianMotionForce< CloudType >::calcCoupled(), MaxwellianThermal< CloudType >::correct(), MixedDiffuseSpecular< CloudType >::correct(), FreeStream< CloudType >::inflow(), GradientDispersionRAS< CloudType >::update(), and StochasticDispersionRAS< CloudType >::update().

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

◆ sample01() [1/2]

Type sample01
inline

Advance the state and return a sample of a given type from a.

uniform distribution between zero and one

Definition at line 69 of file RandomI.H.

Referenced by randomDecomp::decompose(), polygonTriangulate::randomPolygon(), and SHF< CloudType >::update().

Here is the caller graph for this function:

◆ sampleAB() [1/3]

Type sampleAB ( const Type &  a,
const Type &  b 
)
inline

Advance the state and return a sample of a given type from a.

uniform distribution between two limits

Definition at line 97 of file RandomI.H.

References b, and Foam::cmptMultiply().

Referenced by randomRenumber::renumber(), MomentumLookupTableInjection< CloudType >::setPositionAndCell(), ReactingLookupTableInjection< CloudType >::setPositionAndCell(), ReactingMultiphaseLookupTableInjection< CloudType >::setPositionAndCell(), and ThermoLookupTableInjection< CloudType >::setPositionAndCell().

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

◆ sampleNormal() [1/2]

Type sampleNormal
inline

Advance the state and return a sample of a given type from a.

normal distribution with mean zero and standard deviation one

Definition at line 118 of file RandomI.H.

◆ globalScalar01()

Foam::scalar globalScalar01 ( )

Advance the state and return a scalar sample from a uniform.

distribution between zero and one. Synchronises across all cores. Use of this is discouraged. It is expensive and introduces non-randomness in all cores other then the master.

Definition at line 94 of file Random.C.

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

Referenced by PatchFlowRateInjection< CloudType >::nParcelsToInject(), PatchInjection< CloudType >::nParcelsToInject(), patchInjectionBase::setPositionAndCell(), and ConeInjection< CloudType >::setPositionAndCell().

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

◆ permute()

void permute ( Container &  l)
inline

Randomly permute a list.

Definition at line 139 of file RandomI.H.

References Foam::Swap().

Here is the call graph for this function:

◆ sample01() [2/2]

Foam::label sample01 ( )
inline

Definition at line 83 of file RandomI.H.

◆ sampleAB() [2/3]

Foam::scalar sampleAB ( const scalar &  a,
const scalar &  b 
)
inline

Definition at line 104 of file RandomI.H.

References b.

◆ sampleAB() [3/3]

Foam::label sampleAB ( const label a,
const label b 
)
inline

Definition at line 111 of file RandomI.H.

References b.

◆ sampleNormal() [2/2]

Foam::scalar sampleNormal ( )
inline

Definition at line 132 of file RandomI.H.


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