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 [35] .

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/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
  }

  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.

  1. __init__(self: visp._visp.core.UniRand) -> None

  2. __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

__init__

Overloaded function.

next

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

setSeed

Initialize the random number generator.

shuffleVector

Overloaded function.

uniform

Overloaded function.

Inherited Methods

Operators

__doc__

__init__

Overloaded function.

__module__

Attributes

__annotations__

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: visp._visp.core.UniRand) -> None

  2. __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.

Parameters:
initstate: int

Starting state for the RNG, you can pass any 64-bit value.

initseq: int

Select the output sequence for the RNG, you can pass any 64-bit value, although only the low 63 bits are significant.

static shuffleVector(*args, **kwargs)

Overloaded function.

  1. shuffleVector(inputVector: list[int]) -> 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.

Returns:

std::vector<T> A vector containing the same objects than inputVector , but that are shuffled.

  1. shuffleVector(inputVector: list[float]) -> 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.

Returns:

std::vector<T> A vector containing the same objects than inputVector , but that are shuffled.

uniform(*args, **kwargs)

Overloaded function.

  1. 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.

  1. 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.

  1. 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.