cisst-saw
Loading...
Searching...
No Matches
cmnRandomSequence Class Reference

Provide an interface to a reproducible random sequence. More...

#include <cmnRandomSequence.h>

Public Types

typedef unsigned int SeedType
typedef int ElementaryRandomNumber
typedef unsigned long SequenceCounterType

Public Member Functions

SeedType GetSeed (void) const
void SetSeed (const SeedType seed)
SequenceCounterType GetSequencePosition (void) const
void SetSequencePosition (const SequenceCounterType position)
ElementaryRandomNumber ExtractRandomElement (void)
template<typename _valueType>
void ExtractRandomValue (_valueType &result)
template<typename _valueType>
void ExtractRandomValue (const _valueType min, const _valueType max, _valueType &result)
template<typename _valueType>
void ExtractRandomValueArray (const _valueType min, const _valueType max, _valueType *array, const size_t arraySize)
float ExtractRandomFloat (void)
float ExtractRandomFloat (const float min, const float max)
void ExtractRandomFloatArray (const float min, const float max, float *array, const size_t arraySize)
double ExtractRandomDouble (void)
double ExtractRandomDouble (const double min, const double max)
void ExtractRandomDoubleArray (const double min, const double max, double *array, const size_t arraySize)
int ExtractRandomInt (void)
int ExtractRandomInt (const int min, const int max)
void ExtractRandomIntArray (const int min, const int max, int *array, const size_t arraySize)
unsigned int ExtractRandomUnsignedInt (void)
unsigned int ExtractRandomUnsignedInt (const unsigned int min, const unsigned int max)
void ExtractRandomUnsignedIntArray (const unsigned int min, const unsigned int max, unsigned int *array, const size_t arraySize)
short ExtractRandomShort (void)
short ExtractRandomShort (const short min, const short max)
void ExtractRandomShortArray (const short min, const short max, short *array, const size_t arraySize)
unsigned short ExtractRandomUnsignedShort (void)
unsigned short ExtractRandomUnsignedShort (const unsigned short min, const unsigned short max)
void ExtractRandomUnsignedShortArray (const unsigned short min, const unsigned short max, unsigned short *array, const size_t arraySize)
long ExtractRandomLong (void)
long ExtractRandomLong (const long min, const long max)
void ExtractRandomLongArray (const long min, const long max, long *array, const size_t arraySize)
unsigned long ExtractRandomUnsignedLong (void)
unsigned long ExtractRandomUnsignedLong (const unsigned long min, const unsigned long max)
void ExtractRandomUnsignedLongArray (const unsigned long min, const unsigned long max, unsigned long *array, const size_t arraySize)
long long ExtractRandomLongLong (void)
long ExtractRandomLongLong (const long long min, const long long max)
void ExtractRandomLongLongArray (const long long min, const long long max, long long *array, const size_t arraySize)
unsigned long long ExtractRandomUnsignedLongLong (void)
unsigned long long ExtractRandomUnsignedLongLong (const unsigned long long min, const unsigned long long max)
void ExtractRandomUnsignedLongLongArray (const unsigned long long min, const unsigned long long max, unsigned long long *array, const size_t arraySize)
char ExtractRandomChar (void)
char ExtractRandomChar (const char min, const char max)
void ExtractRandomCharArray (const char min, const char max, char *array, const size_t arraySize)
unsigned char ExtractRandomUnsignedChar (void)
unsigned char ExtractRandomUnsignedChar (const unsigned char min, const unsigned char max)
void ExtractRandomUnsignedCharArray (const unsigned char min, const unsigned char max, unsigned char *array, const size_t arraySize)
void ExtractRandomPermutation (const size_t length, size_t *array)
size_t ExtractRandomSizeT (const size_t min, const size_t max)
void ExtractRandomSizeTArray (const size_t min, const size_t max, size_t *array, const size_t arraySize)
ptrdiff_t ExtractRandomPtrdiffT (const ptrdiff_t min, const ptrdiff_t max)
void ExtractRandomPtrdiffTArray (const ptrdiff_t min, const ptrdiff_t max, ptrdiff_t *array, const size_t arraySize)

Static Public Member Functions

static cmnRandomSequenceGetInstance (void)

Static Public Attributes

static const SeedType DefaultSeed
static const ElementaryRandomNumber LowerRandomBound
static const ElementaryRandomNumber UpperRandomBound

Protected Member Functions

 cmnRandomSequence ()
 cmnRandomSequence (const SeedType seed, const SequenceCounterType position=0)
 cmnRandomSequence (const cmnRandomSequence &other)
cmnRandomSequenceoperator= (const cmnRandomSequence &other)

Static Protected Attributes

static cmnRandomSequence RandomInstance

Detailed Description

Provide an interface to a reproducible random sequence.

Class cmnRandomSequence provides a reproducible random sequence. A random sequence is defined as a sequence of elements of type ElementaryRandomNumber, which is generated by a more or less good random number generator. The random number generator is initialized with a seed, and outputs a sequence of numbers.

In order to reproduce a random sequence, we need to store the seed and the position in the sequence. We can then resume to any position in the sequence using the method SetSequencePosition().

Important note: In the current implementation, we are using the rand() function of the standard C/C++ library. However, as the rand() function does not have a cross-platform standardized behavior, our random sequence is only reproducible within the scope of one compiler on one machine. In addition, as we depend on a global mechanism, all the random sequences use the same resource. This means that in fact, there is only one random sequence in the system. Therefore, the current implementation is as a Singleton.

Useful background on randomization can be found, for example, in Numerical Recipes: http://www.nr.com . Due to copyright issues, we are currently delaying its use. Another possible source for randomization functions is in the Gnu Scientific Library (GSL): http://www.gnu.org/software/gsl/gsl.html .

Member Typedef Documentation

◆ ElementaryRandomNumber

type of the elementary random number that's generated by cmnRandomSequence

◆ SeedType

typedef unsigned int cmnRandomSequence::SeedType

type of the randomization seed

◆ SequenceCounterType

type of counter of the number of elements that were extracted from the sequence

Constructor & Destructor Documentation

◆ cmnRandomSequence() [1/3]

cmnRandomSequence::cmnRandomSequence ( )
inlineprotected

Default constructor – initialize the randomization seed to the default seed and start at the first element of the random sequence.

◆ cmnRandomSequence() [2/3]

cmnRandomSequence::cmnRandomSequence ( const SeedType seed,
const SequenceCounterType position = 0 )
inlineprotected

Parametrized constructor – initialize the randomization seed by a parameter and start at the specified position (zero based) of the random sequence

◆ cmnRandomSequence() [3/3]

cmnRandomSequence::cmnRandomSequence ( const cmnRandomSequence & other)
inlineprotected

Copy constructor – initialize the seed and the sequence position identically to the other object

Member Function Documentation

◆ ExtractRandomChar() [1/2]

char cmnRandomSequence::ExtractRandomChar ( const char min,
const char max )
inline

◆ ExtractRandomChar() [2/2]

char cmnRandomSequence::ExtractRandomChar ( void )
inline

◆ ExtractRandomCharArray()

void cmnRandomSequence::ExtractRandomCharArray ( const char min,
const char max,
char * array,
const size_t arraySize )
inline

◆ ExtractRandomDouble() [1/2]

double cmnRandomSequence::ExtractRandomDouble ( const double min,
const double max )
inline

Return a random double-precision floating point number in the range [min..max]

◆ ExtractRandomDouble() [2/2]

double cmnRandomSequence::ExtractRandomDouble ( void )
inline

Return a random double-precision floating point number in the range (0..1)

◆ ExtractRandomDoubleArray()

void cmnRandomSequence::ExtractRandomDoubleArray ( const double min,
const double max,
double * array,
const size_t arraySize )
inline

◆ ExtractRandomElement()

ElementaryRandomNumber cmnRandomSequence::ExtractRandomElement ( void )
inline

Extract a single random element from the sequence. This is the basic operation on the random sequence.

◆ ExtractRandomFloat() [1/2]

float cmnRandomSequence::ExtractRandomFloat ( const float min,
const float max )
inline

Return a random floating point number in the range [min..max]

◆ ExtractRandomFloat() [2/2]

float cmnRandomSequence::ExtractRandomFloat ( void )
inline

Return a random floating point number in the range (0..1)

◆ ExtractRandomFloatArray()

void cmnRandomSequence::ExtractRandomFloatArray ( const float min,
const float max,
float * array,
const size_t arraySize )
inline

◆ ExtractRandomInt() [1/2]

int cmnRandomSequence::ExtractRandomInt ( const int min,
const int max )
inline

◆ ExtractRandomInt() [2/2]

int cmnRandomSequence::ExtractRandomInt ( void )
inline

◆ ExtractRandomIntArray()

void cmnRandomSequence::ExtractRandomIntArray ( const int min,
const int max,
int * array,
const size_t arraySize )
inline

◆ ExtractRandomLong() [1/2]

long cmnRandomSequence::ExtractRandomLong ( const long min,
const long max )
inline

◆ ExtractRandomLong() [2/2]

long cmnRandomSequence::ExtractRandomLong ( void )
inline

◆ ExtractRandomLongArray()

void cmnRandomSequence::ExtractRandomLongArray ( const long min,
const long max,
long * array,
const size_t arraySize )
inline

◆ ExtractRandomLongLong() [1/2]

long cmnRandomSequence::ExtractRandomLongLong ( const long long min,
const long long max )
inline

◆ ExtractRandomLongLong() [2/2]

long long cmnRandomSequence::ExtractRandomLongLong ( void )
inline

◆ ExtractRandomLongLongArray()

void cmnRandomSequence::ExtractRandomLongLongArray ( const long long min,
const long long max,
long long * array,
const size_t arraySize )
inline

◆ ExtractRandomPermutation()

void cmnRandomSequence::ExtractRandomPermutation ( const size_t length,
size_t * array )

Fill the given array with a random permutation of the numbers 0..length

◆ ExtractRandomPtrdiffT()

ptrdiff_t cmnRandomSequence::ExtractRandomPtrdiffT ( const ptrdiff_t min,
const ptrdiff_t max )
inline

◆ ExtractRandomPtrdiffTArray()

void cmnRandomSequence::ExtractRandomPtrdiffTArray ( const ptrdiff_t min,
const ptrdiff_t max,
ptrdiff_t * array,
const size_t arraySize )
inline

◆ ExtractRandomShort() [1/2]

short cmnRandomSequence::ExtractRandomShort ( const short min,
const short max )
inline

◆ ExtractRandomShort() [2/2]

short cmnRandomSequence::ExtractRandomShort ( void )
inline

◆ ExtractRandomShortArray()

void cmnRandomSequence::ExtractRandomShortArray ( const short min,
const short max,
short * array,
const size_t arraySize )
inline

◆ ExtractRandomSizeT()

size_t cmnRandomSequence::ExtractRandomSizeT ( const size_t min,
const size_t max )
inline

Specialized versions for size_t and ptrdiff_t. We have to create new methods for these types instead of overloading since some compilers don't define these as native types but typedefs. If these types are typdefs, it is not possible to overload methods or specialize templates as these would conflict with the native types int 32/64 singed/unsigned based on OS/Compiler data model (i.e. LP64 or LLP64).

◆ ExtractRandomSizeTArray()

void cmnRandomSequence::ExtractRandomSizeTArray ( const size_t min,
const size_t max,
size_t * array,
const size_t arraySize )
inline

◆ ExtractRandomUnsignedChar() [1/2]

unsigned char cmnRandomSequence::ExtractRandomUnsignedChar ( const unsigned char min,
const unsigned char max )
inline

◆ ExtractRandomUnsignedChar() [2/2]

unsigned char cmnRandomSequence::ExtractRandomUnsignedChar ( void )
inline

◆ ExtractRandomUnsignedCharArray()

void cmnRandomSequence::ExtractRandomUnsignedCharArray ( const unsigned char min,
const unsigned char max,
unsigned char * array,
const size_t arraySize )
inline

◆ ExtractRandomUnsignedInt() [1/2]

unsigned int cmnRandomSequence::ExtractRandomUnsignedInt ( const unsigned int min,
const unsigned int max )
inline

◆ ExtractRandomUnsignedInt() [2/2]

unsigned int cmnRandomSequence::ExtractRandomUnsignedInt ( void )
inline

◆ ExtractRandomUnsignedIntArray()

void cmnRandomSequence::ExtractRandomUnsignedIntArray ( const unsigned int min,
const unsigned int max,
unsigned int * array,
const size_t arraySize )
inline

◆ ExtractRandomUnsignedLong() [1/2]

unsigned long cmnRandomSequence::ExtractRandomUnsignedLong ( const unsigned long min,
const unsigned long max )
inline

◆ ExtractRandomUnsignedLong() [2/2]

unsigned long cmnRandomSequence::ExtractRandomUnsignedLong ( void )
inline

◆ ExtractRandomUnsignedLongArray()

void cmnRandomSequence::ExtractRandomUnsignedLongArray ( const unsigned long min,
const unsigned long max,
unsigned long * array,
const size_t arraySize )
inline

◆ ExtractRandomUnsignedLongLong() [1/2]

unsigned long long cmnRandomSequence::ExtractRandomUnsignedLongLong ( const unsigned long long min,
const unsigned long long max )
inline

◆ ExtractRandomUnsignedLongLong() [2/2]

unsigned long long cmnRandomSequence::ExtractRandomUnsignedLongLong ( void )
inline

◆ ExtractRandomUnsignedLongLongArray()

void cmnRandomSequence::ExtractRandomUnsignedLongLongArray ( const unsigned long long min,
const unsigned long long max,
unsigned long long * array,
const size_t arraySize )
inline

◆ ExtractRandomUnsignedShort() [1/2]

unsigned short cmnRandomSequence::ExtractRandomUnsignedShort ( const unsigned short min,
const unsigned short max )
inline

◆ ExtractRandomUnsignedShort() [2/2]

unsigned short cmnRandomSequence::ExtractRandomUnsignedShort ( void )
inline

◆ ExtractRandomUnsignedShortArray()

void cmnRandomSequence::ExtractRandomUnsignedShortArray ( const unsigned short min,
const unsigned short max,
unsigned short * array,
const size_t arraySize )
inline

◆ ExtractRandomValue() [1/2]

template<typename _valueType>
void cmnRandomSequence::ExtractRandomValue ( _valueType & result)

Extract a random value for a templated type. These methods are specialized by the type argument so that they can be used generically, e.g., in sequence testing.

◆ ExtractRandomValue() [2/2]

template<typename _valueType>
void cmnRandomSequence::ExtractRandomValue ( const _valueType min,
const _valueType max,
_valueType & result )
inline

◆ ExtractRandomValueArray()

template<typename _valueType>
CISST_DEFINE_TEMPLATE_FUNCTION_SPECIALIZATION void cmnRandomSequence::ExtractRandomValueArray ( const _valueType min,
const _valueType max,
_valueType * array,
const size_t arraySize )
inline

◆ GetInstance()

cmnRandomSequence & cmnRandomSequence::GetInstance ( void )
inlinestatic

Access the Singleton instance

◆ GetSeed()

SeedType cmnRandomSequence::GetSeed ( void ) const
inline

Return the randomization seed for this object

◆ GetSequencePosition()

SequenceCounterType cmnRandomSequence::GetSequencePosition ( void ) const
inline

Return the number of random sequence elements extracted so far.

◆ operator=()

cmnRandomSequence & cmnRandomSequence::operator= ( const cmnRandomSequence & other)
inlineprotected

Assignment operator – see copy constructor

◆ SetSeed()

void cmnRandomSequence::SetSeed ( const SeedType seed)
inline

Set the randomization seed to the given value, and move to sequence position 0.

◆ SetSequencePosition()

void cmnRandomSequence::SetSequencePosition ( const SequenceCounterType position)
inline

Move to the specified position (zero based) in the random sequence starting with the current seed.

Member Data Documentation

◆ DefaultSeed

const SeedType cmnRandomSequence::DefaultSeed
static

The default randomization seed.

◆ LowerRandomBound

const ElementaryRandomNumber cmnRandomSequence::LowerRandomBound
static

the lower bound for a value of an elementary random number

◆ RandomInstance

cmnRandomSequence cmnRandomSequence::RandomInstance
staticprotected

The Singleton instance

◆ UpperRandomBound

const ElementaryRandomNumber cmnRandomSequence::UpperRandomBound
static

the upper bound for a value of an elementary random number


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