Visual Servoing Platform
version 3.6.1 under development (2024-11-21)
|
#include <visp3/core/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) |
Static Public Member Functions | |
template<typename T > | |
static std::vector< T > | shuffleVector (const std::vector< T > &inputVector, const int32_t &seed=-1) |
Class for generating random numbers with uniform probability density.
The algorithms and notations used are described in [41].
The following example also available in random.cpp shows how to use this class to generate 10 numbers between 0 and 5.
Once build, this previous code should produces an output similar to the following:
Definition at line 126 of file vpUniRand.h.
BEGIN_VISP_NAMESPACE 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.
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. |
Definition at line 84 of file vpUniRand.cpp.
References setSeed().
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 145 of file vpUniRand.cpp.
Referenced by vpMbtDistanceLine::buildFrom(), 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 94 of file vpUniRand.cpp.
References uniform().
void vpUniRand::setSeed | ( | uint64_t | initstate, |
uint64_t | initseq | ||
) |
Initialize the random number generator.
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. |
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 202 of file vpUniRand.cpp.
References next().
Referenced by vpParticleFilter< MeasurementsType >::vpParticleFilter(), and vpUniRand().
|
inlinestatic |
Create a new vector that is a shuffled version of the inputVector.
T | : A class that possesses a copy constructor. |
inputVector | : The input vector that must be shuffled. It will not be modified. |
seed | : The seed value. |
Definition at line 149 of file vpUniRand.h.
double vpUniRand::uniform | ( | double | a, |
double | b | ||
) |
Generates a pseudorandom uniformly distributed double number between [a, b) range.
a | : lower inclusive boundary of the returned random number. |
b | : upper non-inclusive boundary of the returned random number. |
Definition at line 179 of file vpUniRand.cpp.
References next().
float vpUniRand::uniform | ( | float | a, |
float | b | ||
) |
Generates a pseudorandom uniformly distributed float number between [a, b) range.
a | : lower inclusive boundary of the returned random number. |
b | : upper non-inclusive boundary of the returned random number. |
Definition at line 172 of file vpUniRand.cpp.
References next().
int vpUniRand::uniform | ( | int | a, |
int | b | ||
) |
Generates a pseudorandom uniformly distributed int number between [a, b) range.
a | : lower inclusive boundary of the returned random number. |
b | : upper non-inclusive boundary of the returned random number. |
Definition at line 159 of file vpUniRand.cpp.
Referenced by operator()(), and vpParticleFilter< MeasurementsType >::vpParticleFilter().