UniRand¶
- class UniRand(*args, **kwargs)¶
Bases:
pybind11_object
Class for generating random numbers with uniform probability density.
The algorithms and notations used are described in [37] .
The following example also available in random.cpp shows how to use this class to generate 10 numbers between 0 and 5.
#include <iostream> #include <visp3/core/vpConfig.h> #include <visp3/core/vpUniRand.h> int main() { #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME ; #endif 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 } std::vector<int> v; for (unsigned int i = 0; i < 10; i++) { v.push_back(i); } std::vector<int> shuffled_v = vpUniRand::shuffleVector<int>(v); std::cout << "Original vector = [\t"; for (unsigned int i = 0; i < 10; i++) { std::cout << v[i] << "\t"; } std::cout << "]" << std::endl; std::cout << "Shuffled vector = [\t"; for (unsigned int i = 0; i < 10; i++) { std::cout << shuffled_v[i] << "\t"; } std::cout << "]" << std::endl; }
Once build, this previous code should produces an output similar to the following:
1 0.0582619 1 5.84875 1 3.86449 1 0.216396 5 5.41692 1 1.65448 0 3.31304 4 2.70563 0 4.86741 2 5.65826 Original vector = [ 0 1 2 3 4 5 6 7 8 9 ] Shuffled vector = [ 2 4 7 8 5 1 3 6 9 0 ]
Overloaded function.
__init__(self: visp._visp.core.UniRand) -> None
__init__(self: visp._visp.core.UniRand, seed: int, seq: int = 0x123465789ULL) -> None
Create a pseudorandom number generator with uniform distribution.
Note
See setSeed
- 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.
Methods
Overloaded function.
Generates a pseudorandom uniformly distributed 32-bit unsigned integer (i.e., x where, 0 <= x < 2^32)
Initialize the random number generator.
Overloaded function.
Overloaded function.
Inherited Methods
Operators
__doc__
Overloaded function.
__module__
Attributes
__annotations__
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.UniRand) -> None
__init__(self: visp._visp.core.UniRand, seed: int, seq: int = 0x123465789ULL) -> None
Create a pseudorandom number generator with uniform distribution.
Note
See setSeed
- 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.
- next(self) int ¶
Generates a pseudorandom uniformly distributed 32-bit unsigned integer (i.e., x where, 0 <= x < 2^32)
- setSeed(self, initstate: int, initseq: int) None ¶
Initialize the random number generator.
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.
- static shuffleVector(*args, **kwargs)¶
Overloaded function.
shuffleVector(inputVector: list[int], seed: int = -1) -> list[int]
Create a new vector that is a shuffled version of the inputVector .
- Parameters:
- inputVector
The input vector that must be shuffled. It will not be modified.
- seed
The seed value.
- Returns:
std::vector<T> A vector containing the same objects than inputVector , but that are shuffled.
shuffleVector(inputVector: list[float], seed: int = -1) -> list[float]
Create a new vector that is a shuffled version of the inputVector .
- Parameters:
- inputVector
The input vector that must be shuffled. It will not be modified.
- seed
The seed value.
- Returns:
std::vector<T> A vector containing the same objects than inputVector , but that are shuffled.
- uniform(*args, **kwargs)¶
Overloaded function.
uniform(self: visp._visp.core.UniRand, a: int, b: int) -> int
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.
uniform(self: visp._visp.core.UniRand, a: float, b: float) -> float
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.
uniform(self: visp._visp.core.UniRand, a: float, b: float) -> float
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.