randomGenerator Class Reference

Random number generator. More...

Classes

class  seed
 Seed class. More...
 

Public Member Functions

 randomGenerator (const seed s, const bool global=false)
 Construct from a seed. More...
 
 randomGenerator (const randomGenerator &)
 Copy construct. More...
 
 randomGenerator (randomGenerator &&)
 Move construct. More...
 
 randomGenerator (Istream &is, const bool global=false)
 Construct from a stream. More...
 
 randomGenerator (const word &name, const dictionary &dict, randomGenerator &&defaultRndGen)
 Construct from a dictionary. More...
 
 randomGenerator (const word &name, const dictionary &dict, const seed defaultS, const bool global=false)
 Construct from a dictionary. More...
 
 ~randomGenerator ()
 Destructor. More...
 
scalar scalar01 ()
 Return a scalar uniformly distributed between zero and one. More...
 
tmp< scalarFieldscalar01 (const label n)
 Return scalars uniformly distributed between zero and one. More...
 
scalar scalarAB (const scalar a, const scalar b)
 Return a scalar uniformly distributed between two limits. More...
 
tmp< scalarFieldscalarAB (const label n, const scalar a, const scalar b)
 Return scalars uniformly distributed between two limits. More...
 
template<class Type >
Type sample01 ()
 Return a type with components uniformly distributed between. More...
 
template<class Type >
tmp< Field< Type > > sample01 (const label n)
 Return types with components uniformly distributed between zero. More...
 
template<class Type >
Type sampleAB (const Type &a, const Type &b)
 Return a type with components uniformly distributed between two. More...
 
template<class Type >
tmp< Field< Type > > sampleAB (const label n, const Type &a, const Type &b)
 Return types with components uniformly distributed between two. More...
 
template<class Container >
void permute (Container &l)
 Randomly permute a list. More...
 
randomGenerator generator ()
 Create a randomly seeded generator. More...
 
void operator= (const randomGenerator &)
 Copy-assignment. More...
 
void operator= (randomGenerator &&)
 Move-assignment. More...
 
template<>
scalar sample01NoCheckSync ()
 
template<>
scalar sampleABNoCheckSync (const scalar &a, const scalar &b)
 
template<>
label sampleABNoCheckSync (const label &a, const label &b)
 
template<class Type >
Foam::tmp< Foam::Field< Type > > sample01 (const label n)
 
template<class Type >
Foam::tmp< Foam::Field< Type > > sampleAB (const label n, const Type &a, const Type &b)
 

Friends

Istreamoperator>> (Istream &, randomGenerator &)
 Read from stream. More...
 
Ostreamoperator<< (Ostream &, const randomGenerator &)
 Write to stream. More...
 

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 67 of file randomGenerator.H.

Constructor & Destructor Documentation

◆ randomGenerator() [1/6]

randomGenerator ( const seed  s,
const bool  global = false 
)
inline

Construct from a seed.

Definition at line 152 of file randomGeneratorI.H.

◆ randomGenerator() [2/6]

randomGenerator ( const randomGenerator rndGen)
inline

Copy construct.

Definition at line 161 of file randomGeneratorI.H.

◆ randomGenerator() [3/6]

randomGenerator ( randomGenerator &&  rndGen)
inline

Move construct.

Definition at line 170 of file randomGeneratorI.H.

◆ randomGenerator() [4/6]

randomGenerator ( Istream is,
const bool  global = false 
)

Construct from a stream.

Definition at line 31 of file randomGenerator.C.

◆ randomGenerator() [5/6]

randomGenerator ( const word name,
const dictionary dict,
randomGenerator &&  defaultRndGen 
)

Construct from a dictionary.

Definition at line 40 of file randomGenerator.C.

◆ randomGenerator() [6/6]

randomGenerator ( const word name,
const dictionary dict,
const seed  defaultS,
const bool  global = false 
)

Construct from a dictionary.

Definition at line 59 of file randomGenerator.C.

◆ ~randomGenerator()

~randomGenerator ( )
inline

Destructor.

Definition at line 178 of file randomGeneratorI.H.

Member Function Documentation

◆ scalar01() [1/2]

◆ scalar01() [2/2]

Foam::tmp< Foam::scalarField > scalar01 ( const label  n)
inline

Return scalars uniformly distributed between zero and one.

Definition at line 194 of file randomGeneratorI.H.

References n, and tmp< T >::ref().

Here is the call graph for this function:

◆ scalarAB() [1/2]

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

Return a scalar uniformly distributed between two limits.

Definition at line 212 of file randomGeneratorI.H.

References b.

◆ scalarAB() [2/2]

Foam::tmp< Foam::scalarField > scalarAB ( const label  n,
const scalar  a,
const scalar  b 
)
inline

Return scalars uniformly distributed between two limits.

Definition at line 226 of file randomGeneratorI.H.

References b, n, and tmp< T >::ref().

Here is the call graph for this function:

◆ sample01() [1/3]

Type sample01
inline

Return a type with components uniformly distributed between.

zero and one

Definition at line 247 of file randomGeneratorI.H.

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

Here is the caller graph for this function:

◆ sample01() [2/3]

tmp<Field<Type> > sample01 ( const label  n)
inline

Return types with components uniformly distributed between zero.

and one

◆ sampleAB() [1/3]

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

◆ sampleAB() [2/3]

tmp<Field<Type> > sampleAB ( const label  n,
const Type &  a,
const Type &  b 
)
inline

Return types with components uniformly distributed between two.

limits

◆ permute()

void permute ( Container &  l)
inline

Randomly permute a list.

Definition at line 309 of file randomGeneratorI.H.

References Foam::Swap().

Here is the call graph for this function:

◆ generator()

Foam::randomGenerator generator ( )
inline

Create a randomly seeded generator.

Definition at line 322 of file randomGeneratorI.H.

◆ operator=() [1/2]

void operator= ( const randomGenerator rndGen)

Copy-assignment.

Definition at line 73 of file randomGenerator.C.

References Foam::exit(), Foam::FatalError, FatalErrorInFunction, and rndGen().

Here is the call graph for this function:

◆ operator=() [2/2]

void operator= ( randomGenerator &&  rndGen)

Move-assignment.

Definition at line 88 of file randomGenerator.C.

References rndGen().

Here is the call graph for this function:

◆ sample01NoCheckSync()

Foam::label sample01NoCheckSync ( )
inline

Definition at line 92 of file randomGeneratorI.H.

◆ sampleABNoCheckSync() [1/2]

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

Definition at line 117 of file randomGeneratorI.H.

References b.

◆ sampleABNoCheckSync() [2/2]

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

Definition at line 128 of file randomGeneratorI.H.

References b.

◆ sample01() [3/3]

Foam::tmp<Foam::Field<Type> > sample01 ( const label  n)
inline

Definition at line 258 of file randomGeneratorI.H.

References n, and tmp< T >::ref().

Here is the call graph for this function:

◆ sampleAB() [3/3]

Foam::tmp<Foam::Field<Type> > sampleAB ( const label  n,
const Type &  a,
const Type &  b 
)
inline

Definition at line 288 of file randomGeneratorI.H.

References b, n, and tmp< T >::ref().

Here is the call graph for this function:

Friends And Related Function Documentation

◆ operator>>

Istream& operator>> ( Istream ,
randomGenerator  
)
friend

Read from stream.

◆ operator<<

Ostream& operator<< ( Ostream ,
const randomGenerator  
)
friend

Write to stream.


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