YARP
Yet Another Robot Platform
Random.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #include <yarp/os/Random.h>
7 
8 #include <cmath>
9 #include <cstdlib>
10 #include <random>
11 
12 using namespace yarp::os;
13 std::default_random_engine randengine;
14 
16 {
17  std::uniform_real_distribution<double> udist(0.0, 1.0);
18  return udist(randengine);
19 }
20 
22 {
23  return normal(0.0, 1.0);
24 }
25 
26 double Random::normal(double m, double s)
27 {
28  std::normal_distribution<double> ndist(m, s);
29  return ndist(randengine);
30 }
31 
32 void Random::seed(int seed)
33 {
34  randengine.seed(seed);
35 }
36 
37 
38 int Random::uniform(int min, int max)
39 {
40  std::uniform_int_distribution<int> udist(min, max);
41  return udist(randengine);
42 }
std::default_random_engine randengine
Definition: Random.cpp:13
Contains methods and classes for generating random numbers with various (simple) distributions.
static double normal()
Definition: Random.cpp:21
static double uniform()
Generates a random number in the range 0 to 1.
Definition: Random.cpp:15
static void seed(int seed)
Sets the seed of the random number generator.
Definition: Random.cpp:32
An interface to the operating system, including Port based communication.