YARP
Yet Another Robot Platform
Loading...
Searching...
No Matches
RandScalar.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
7
// Sept. 2010 Uses gsl routines for random generation.
8
9
#include <
yarp/math/RandScalar.h
>
10
#include <
yarp/sig/Vector.h
>
11
#include <ctime>
12
#include <cstdio>
13
#include <cmath>
14
15
// implementation of Marsenne Twister from C++11's library
16
#include <random>
17
18
using namespace
yarp::sig
;
19
using namespace
yarp::math
;
20
21
inline
std::mt19937 *
implementation
(
void
*
t
)
22
{
23
return
static_cast<
std::mt19937 *
>
(
t
);
24
}
25
26
RandScalar::RandScalar
()
27
{
28
impl =
new
std::mt19937();
29
init
();
30
}
31
32
RandScalar::RandScalar
(
int
s) :
33
seed(s)
34
{
35
impl =
new
std::mt19937;
36
implementation
(impl)->seed(seed);
37
}
38
39
RandScalar::~RandScalar
()
40
{
41
delete
implementation
(impl);
42
}
43
44
double
RandScalar::get
()
45
{
46
std::uniform_real_distribution<double> dist(0.0, 1.0);
47
return
dist(*(
implementation
(impl)));
48
}
49
50
double
RandScalar::get
(
double
min,
double
max)
51
{
52
std::uniform_real_distribution<double> dist(min, max);
53
return
dist(*(
implementation
(impl)));
54
}
55
56
// initialize with a call to "time"
57
void
RandScalar::init
()
58
{
59
// initialize with time
60
int
t
=(int)time(
nullptr
);
61
RandScalar::init
(
t
);
62
}
63
64
void
RandScalar::init
(
int
s)
65
{
66
seed=s;
67
implementation
(impl)->seed(seed);
68
}
t
float t
Definition
FfmpegWriter.cpp:71
implementation
std::mt19937 * implementation(void *t)
Definition
RandScalar.cpp:21
RandScalar.h
implementation
RandScalar * implementation(void *t)
Definition
RandnScalar.cpp:17
Vector.h
contains the definition of a Vector type
yarp::math::RandScalar::RandScalar
RandScalar()
Definition
RandScalar.cpp:26
yarp::math::RandScalar::~RandScalar
~RandScalar()
Definition
RandScalar.cpp:39
yarp::math::RandScalar::init
void init()
Initialize the random generator using current time (time(0)).
Definition
RandScalar.cpp:57
yarp::math::RandScalar::get
double get()
Generate a random number from a uniform distribution.
Definition
RandScalar.cpp:44
yarp::math
Definition
FrameTransform.h:14
yarp::sig
Definition
audioBufferSizeData.cpp:13
YARP
3.10.1+35-20241205.6+git6b4bb23ab
src
libYARP_math
src
yarp
math
RandScalar.cpp
Generated on Thu Dec 12 2024 02:37:46 for YARP by
1.9.8