 Visual Servoing Platform  version 3.5.1 under development (2022-07-05)
vpUniRand Class Reference

`#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)

## Detailed Description

Class for generating random numbers with uniform probability density.

The algorithms and notations used are described in .

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
}
}
Class for generating random numbers with uniform probability density.
Definition: vpUniRand.h:101
int uniform(int a, int b)
Definition: vpUniRand.cpp:160
Examples
tutorial-munkres-assignment.cpp.

Definition at line 100 of file vpUniRand.h.

## ◆ vpUniRand() [1/2]

 vpUniRand::vpUniRand ( )

Definition at line 72 of file vpUniRand.cpp.

## ◆ vpUniRand() [2/2]

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

Definition at line 85 of file vpUniRand.cpp.

References setSeed().

## ◆ next()

 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 146 of file vpUniRand.cpp.

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

## ◆ operator()()

 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 uniform().

## ◆ setSeed()

 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 203 of file vpUniRand.cpp.

References next().

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

## ◆ uniform() [1/3]

 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 180 of file vpUniRand.cpp.

References next().

## ◆ uniform() [2/3]

 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 173 of file vpUniRand.cpp.

References next().

## ◆ uniform() [3/3]

 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 160 of file vpUniRand.cpp.

Referenced by operator()().