![]() |
Visual Servoing Platform
version 3.3.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) |
Class for generating random numbers with uniform probability density.
The algorithms and notations used are described in [oneill:pcg2014].
The following example shows how to use this class to generate 10 numbers between 0 and 5.
Definition at line 99 of file vpUniRand.h.
vpUniRand::vpUniRand | ( | ) |
Definition at line 71 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.
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 148 of file vpUniRand.cpp.
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.
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 211 of file vpUniRand.cpp.
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 185 of file vpUniRand.cpp.
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 175 of file vpUniRand.cpp.
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 162 of file vpUniRand.cpp.