YARP
Yet Another Robot Platform
NormRand.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #include <yarp/math/NormRand.h>
11 #include <yarp/math/RandnScalar.h>
12 
13 using namespace yarp::math;
14 
15 /* should be thread safe, from gsl */
17 
18 double NormRand::scalar(double u, double sigma)
19 {
20  return theRandnScalar.get(u,sigma);
21 }
22 
23 yarp::sig::Vector NormRand::vector(int s, double u, double sigma)
24 {
25  yarp::sig::Vector ret((size_t) s);
26  for(int k=0;k<s;k++)
27  {
28  ret[k]=theRandnScalar.get(u, sigma);
29  }
30 
31  return ret;
32 }
33 
35 {
37  for(size_t k=0;k<u.length();k++)
38  {
39  ret[k]=theRandnScalar.get(u[k], sigma[k]);
40  }
41 
42  return ret;
43 }
44 
45 yarp::sig::Matrix NormRand::matrix(int rows, int cols, double u, double sigma)
46 {
47  yarp::sig::Matrix ret(rows,cols);
48  for(int r=0;r<rows;r++)
49  for(int c=0;c<cols;c++)
50  {
51  ret[r][c]=theRandnScalar.get(u, sigma);
52  }
53  return ret;
54 }
55 
57 {
59 }
60 
61 void NormRand::init(int seed)
62 {
63  theRandnScalar.init(seed);
64 }
yarp::math::NormRand::matrix
static yarp::sig::Matrix matrix(int r, int c, double u=0.0, double sigma=1.0)
Definition: NormRand.cpp:45
yarp::math::NormRand::vector
static yarp::sig::Vector vector(int s, double u=0.0, double sigma=1.0)
Definition: NormRand.cpp:23
NormRand.h
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::math::NormRand::init
static void init()
Initialize the random number generator, with current time (time(0)).
Definition: NormRand.cpp:56
yarp::math
Definition: FrameTransform.h:18
yarp::math::NormRand::scalar
static double scalar(double u=0.0, double sigma=1.0)
Definition: NormRand.cpp:18
yarp::sig::VectorOf< double >
RandnScalar.h
yarp::math::RandnScalar::init
void init()
Initialize the generator.
Definition: RandnScalar.cpp:43
yarp::sig::VectorOf::length
size_t length() const
Get the length of the vector.
Definition: Vector.h:363
theRandnScalar
yarp::math::RandnScalar theRandnScalar
Definition: NormRand.cpp:16
yarp::math::RandnScalar::get
double get(double u=0.0, double sigma=1.0)
Generate a randomly generated number, drawn from a normal distribution.
Definition: RandnScalar.cpp:58
yarp::math::RandnScalar
A random number generator, normal distribution.
Definition: RandnScalar.h:27
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46