This class implements a random number generator. More...

Public Member Functions


Protected Attributes

SBDTypeRandomData * dataPointer

Constructors and destructors

 SBDTypeRandom ()
 Constructs a random generator with fixed seed.
 SBDTypeRandom (unsigned long s)
 Constructs a random generator with custom seed.
 ~SBDTypeRandom ()
 Destructs the random generator.

Random integer generators

unsigned long randUnsignedLong ()
 Generates a random number on [0,0xffffffff]-interval.
long randLong ()
 Generates a random number on [0,0x7fffffff]-interval.

Random real generators

double randDouble1 ()
 Generates a random number on [0,1]-real-interval.
double randDouble2 ()
 Generates a random number on [0,1)-real-interval.
double randDouble3 ()
 Generates a random number on (0,1)-real-interval.
double randRes53 ()
 Generates a random number on [0,1) with 53-bit resolution.

Random Universally Unique Identifier (UUID) generator

SBCContainerUUID randUUID ()
 Generates a random 32-character hexadecimal chain with the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.

Random vector generators

SBVector3 randUnitSphere3 ()
 Generates a point on the unit 3D sphere with uniform spherical distribution.


void seed (unsigned long)
 Reseed the random generator.

Detailed Description

The class SBDTypeRandom generator implements the Mersenne Twister generator from the paper: M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator", ACM Trans. on Modeling and Computer Simulation Vol. 8, No. 1, January pp.3-30 (1998).

Note that the default constructor of SBDTypeRandom, SBDTypeRandom::SBDTypeRandom(), has a fixed seed. This is useful when debugging code, since it allows for reproducible results. For a "production run", though, a SBDTypeRandom object should be seeded with a random number, for example using SAMSON::getTime():

SBUUID UUID=r.randUUID(); // create a random UUID

Short name: SBRandom

See also