SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
RandHelper.h
Go to the documentation of this file.
1
/****************************************************************************/
9
//
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12
// Copyright (C) 2005-2014 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
#ifndef RandHelper_h
23
#define RandHelper_h
24
25
26
// ===========================================================================
27
// included modules
28
// ===========================================================================
29
#ifdef _MSC_VER
30
#include <
windows_config.h
>
31
#else
32
#include <
config.h
>
33
#endif
34
35
#include <cassert>
36
#include <vector>
37
#include <
foreign/mersenne/MersenneTwister.h
>
38
39
40
// ===========================================================================
41
// class declarations
42
// ===========================================================================
43
class
OptionsCont
;
44
45
46
// ===========================================================================
47
// class definitions
48
// ===========================================================================
53
class
RandHelper
{
54
public
:
56
static
void
insertRandOptions
();
57
59
static
void
initRandGlobal
(
MTRand
* which = 0);
60
62
static
inline
SUMOReal
rand
() {
63
return
(
SUMOReal
)
RandHelper::myRandomNumberGenerator
.
randExc
();
64
}
65
67
static
inline
SUMOReal
rand
(
SUMOReal
maxV) {
68
return
maxV *
rand
();
69
}
70
72
static
inline
SUMOReal
rand
(
SUMOReal
minV,
SUMOReal
maxV) {
73
return
minV + (maxV - minV) *
rand
();
74
}
75
77
static
inline
size_t
rand
(
size_t
maxV) {
78
return
(
size_t
)
RandHelper::myRandomNumberGenerator
.
randInt
((
MTRand::uint32
)(maxV - 1));
79
}
80
82
static
inline
int
rand
(
int
maxV) {
83
return
(
int
)
RandHelper::myRandomNumberGenerator
.
randInt
((
MTRand::uint32
)(maxV - 1));
84
}
85
87
static
inline
int
rand
(
int
minV,
int
maxV) {
88
return
minV +
rand
(maxV - minV);
89
}
90
92
static
inline
SUMOReal
randNorm
(
SUMOReal
mean,
SUMOReal
variance,
MTRand
& rng =
myRandomNumberGenerator
) {
93
return
(
SUMOReal
) rng.randNorm(mean, variance);
94
}
95
97
template
<
class
T>
98
static
inline
T
99
getRandomFrom
(
const
std::vector<T>& v) {
100
assert(v.size() > 0);
101
return
v[
rand
(v.size())];
102
}
103
104
105
protected
:
107
static
MTRand
myRandomNumberGenerator
;
108
109
};
110
111
#endif
112
113
/****************************************************************************/
114
tmp
buildd
sumo-0.21.0+dfsg
src
utils
common
RandHelper.h
Generated on Thu Nov 20 2014 19:49:58 for SUMO - Simulation of Urban MObility by
1.8.1.2