YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
NormRand.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
9
10using namespace yarp::math;
11
12/* should be thread safe, from gsl */
14
15double NormRand::scalar(double u, double sigma)
16{
17 return theRandnScalar.get(u,sigma);
18}
19
20yarp::sig::Vector NormRand::vector(int s, double u, double sigma)
21{
22 yarp::sig::Vector ret((size_t) s);
23 for(int k=0;k<s;k++)
24 {
25 ret[k]=theRandnScalar.get(u, sigma);
26 }
27
28 return ret;
29}
30
32{
34 for(size_t k=0;k<u.length();k++)
35 {
36 ret[k]=theRandnScalar.get(u[k], sigma[k]);
37 }
38
39 return ret;
40}
41
42yarp::sig::Matrix NormRand::matrix(int rows, int cols, double u, double sigma)
43{
44 yarp::sig::Matrix ret(rows,cols);
45 for (int r = 0; r < rows; r++) {
46 for(int c=0;c<cols;c++)
47 {
48 ret[r][c]=theRandnScalar.get(u, sigma);
49 }
50 }
51 return ret;
52}
53
55{
57}
58
59void NormRand::init(int seed)
60{
61 theRandnScalar.init(seed);
62}
bool ret
yarp::math::RandnScalar theRandnScalar
Definition NormRand.cpp:13
static void init()
Initialize the random number generator, with current time (time(0)).
Definition NormRand.cpp:54
static double scalar(double u=0.0, double sigma=1.0)
Definition NormRand.cpp:15
static yarp::sig::Vector vector(int s, double u=0.0, double sigma=1.0)
Definition NormRand.cpp:20
static yarp::sig::Matrix matrix(int r, int c, double u=0.0, double sigma=1.0)
Definition NormRand.cpp:42
A random number generator, normal distribution.
Definition RandnScalar.h:22
double get(double u=0.0, double sigma=1.0)
Generate a randomly generated number, drawn from a normal distribution.
void init()
Initialize the generator.
A class for a Matrix.
Definition Matrix.h:39
size_t length() const
Get the length of the vector.
Definition Vector.h:349