Visual Servoing Platform  version 3.4.0

#include <vpUniRand.h>

Public Member Functions

 vpUniRand ()
 
 vpUniRand (uint64_t seed, uint64_t seq=0x123465789ULL)
 
double operator() ()
 
uint32_t next ()
 
int uniform (int a, int b)
 
float uniform (float a, float b)
 
double uniform (double a, double b)
 
void setSeed (uint64_t initstate, uint64_t initseq)
 

Detailed Description

Class for generating random numbers with uniform probability density.

The algorithms and notations used are described in [35].

The following example shows how to use this class to generate 10 numbers between 0 and 5.

#include <iostream>
#include <visp3/core/vpUniRand.h>
int main()
{
vpUniRand rng;
for (int i = 0; i < 10; i++) {
std::cout << rng.uniform(0, 6) << std::endl; // produces int values
std::cout << rng.uniform(0.0, 6.0) << std::endl; // produces double values
}
}

Definition at line 100 of file vpUniRand.h.

Constructor & Destructor Documentation

vpUniRand::vpUniRand ( )

Definition at line 72 of file vpUniRand.cpp.

vpUniRand::vpUniRand ( uint64_t  seed,
uint64_t  seq = 0x123465789ULL 
)

Create a pseudorandom number generator with uniform distribution.

Parameters
seed: Starting state for the RNG, you can pass any 64-bit value.
seq: Select the output sequence for the RNG, you can pass any 64-bit value, although only the low 63 bits are significant.
See also
setSeed

Definition at line 85 of file vpUniRand.cpp.

References setSeed().

Member Function Documentation

uint32_t vpUniRand::next ( void  )

Generates a pseudorandom uniformly distributed 32-bit unsigned integer (i.e., x where, 0 <= x < 2^32)

Definition at line 149 of file vpUniRand.cpp.

Referenced by vpMbtDistanceLine::buildFrom(), operator()(), setSeed(), and uniform().

double vpUniRand::operator() ( )

Generates a pseudorandom uniformly distributed double number between [0, 1) range. This is equivalent to call uniform(0.0, 1.0);

Definition at line 95 of file vpUniRand.cpp.

References next(), and uniform().

void vpUniRand::setSeed ( uint64_t  initstate,
uint64_t  initseq 
)

Initialize the random number generator.

Parameters
initstate: Starting state for the RNG, you can pass any 64-bit value.
initseq: Select the output sequence for the RNG, you can pass any 64-bit value, although only the low 63 bits are significant.
Note

For this generator, there are 2^63 possible sequences of pseudorandom numbers. Each sequence is entirely distinct and has a period of 2^64. The initseq argument selects which stream you will use. The initstate argument specifies where you are in that 264 period.

Calling setSeed with the same arguments produces the same output, allowing programs to use random number sequences repeatably.

If you want truly nondeterministic output for each run of your program, you should pass values that will be different from run to run. On a Unix system, /dev/random provides random bytes that can be used for initialization, but if you want a quick and dirty way to do the initialization, one option is to pass the current time and the address of the RNG itself.

Definition at line 212 of file vpUniRand.cpp.

References next().

Referenced by vpGaussRand::seed(), and vpUniRand().

int vpUniRand::uniform ( int  a,
int  b 
)

Generates a pseudorandom uniformly distributed int number between [a, b) range.

Parameters
a: lower inclusive boundary of the returned random number.
b: upper non-inclusive boundary of the returned random number.

Definition at line 163 of file vpUniRand.cpp.

Referenced by operator()().

float vpUniRand::uniform ( float  a,
float  b 
)

Generates a pseudorandom uniformly distributed float number between [a, b) range.

Parameters
a: lower inclusive boundary of the returned random number.
b: upper non-inclusive boundary of the returned random number.

Definition at line 176 of file vpUniRand.cpp.

References next().

double vpUniRand::uniform ( double  a,
double  b 
)

Generates a pseudorandom uniformly distributed double number between [a, b) range.

Parameters
a: lower inclusive boundary of the returned random number.
b: upper non-inclusive boundary of the returned random number.

Definition at line 186 of file vpUniRand.cpp.

References next().