YARP
Yet Another Robot Platform
yarp::math::RandScalar Class Reference

A random number generator, uniform in the range 0-1. More...

#include <yarp/math/RandScalar.h>

+ Inheritance diagram for yarp::math::RandScalar:

Public Member Functions

 RandScalar (int seed)
 
 RandScalar ()
 
 ~RandScalar ()
 
void init ()
 Initialize the random generator using current time (time(0)). More...
 
void init (int seed)
 Initialize the random generator. More...
 
int getSeed ()
 Get the seed. More...
 
double get ()
 Generate a random number from a uniform distribution. More...
 
double get (double min, double max)
 Generate a random number from a uniform distribution within [min, max]. More...
 

Detailed Description

A random number generator, uniform in the range 0-1.

This class is a simple wrapper around C++11 Mersenne Twister engine.

The generator is always initialized with a seed equal to the current time. You can reset the seed by explicitly calling Rand::init(seed).

Default generator is std::mt19937.

Definition at line 31 of file RandScalar.h.

Constructor & Destructor Documentation

◆ RandScalar() [1/2]

RandScalar::RandScalar ( int  seed)

Definition at line 35 of file RandScalar.cpp.

◆ RandScalar() [2/2]

RandScalar::RandScalar ( )

Definition at line 29 of file RandScalar.cpp.

◆ ~RandScalar()

RandScalar::~RandScalar ( )

Definition at line 42 of file RandScalar.cpp.

Member Function Documentation

◆ get() [1/2]

double RandScalar::get ( )

Generate a random number from a uniform distribution.

Returns
the random value.

Definition at line 47 of file RandScalar.cpp.

◆ get() [2/2]

double RandScalar::get ( double  min,
double  max 
)

Generate a random number from a uniform distribution within [min, max].

Returns
the random value.

Definition at line 53 of file RandScalar.cpp.

◆ getSeed()

int yarp::math::RandScalar::getSeed ( )
inline

Get the seed.

Returns
the seed.

Definition at line 57 of file RandScalar.h.

◆ init() [1/2]

void RandScalar::init ( )

Initialize the random generator using current time (time(0)).

Definition at line 60 of file RandScalar.cpp.

◆ init() [2/2]

void RandScalar::init ( int  seed)

Initialize the random generator.

Parameters
seedthe seed.

Definition at line 67 of file RandScalar.cpp.


The documentation for this class was generated from the following files: