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
/****************************************************************************/
8
//
9
/****************************************************************************/
10
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
12
/****************************************************************************/
13
//
14
// This file is part of SUMO.
15
// SUMO is free software: you can redistribute it and/or modify
16
// it under the terms of the GNU General Public License as published by
17
// the Free Software Foundation, either version 3 of the License, or
18
// (at your option) any later version.
19
//
20
/****************************************************************************/
21
#ifndef RandHelper_h
22
#define RandHelper_h
23
24
25
// ===========================================================================
26
// included modules
27
// ===========================================================================
28
#ifdef _MSC_VER
29
#include <
windows_config.h
>
30
#else
31
#include <
config.h
>
32
#endif
33
34
#include <cassert>
35
#include <vector>
36
#include <
foreign/mersenne/MersenneTwister.h
>
37
38
39
// ===========================================================================
40
// class declarations
41
// ===========================================================================
42
class
OptionsCont
;
43
44
45
// ===========================================================================
46
// class definitions
47
// ===========================================================================
52
class
RandHelper
{
53
public
:
55
static
void
insertRandOptions
();
56
58
static
void
initRandGlobal
(
MTRand
* which = 0);
59
61
static
inline
SUMOReal
rand
() {
62
return
(
SUMOReal
)
RandHelper::myRandomNumberGenerator
.
randExc
();
63
}
64
66
static
inline
SUMOReal
rand
(
SUMOReal
maxV) {
67
return
maxV *
rand
();
68
}
69
71
static
inline
SUMOReal
rand
(
SUMOReal
minV,
SUMOReal
maxV) {
72
return
minV + (maxV - minV) *
rand
();
73
}
74
76
static
inline
size_t
rand
(
size_t
maxV) {
77
return
(
size_t
)
RandHelper::myRandomNumberGenerator
.
randInt
((
MTRand::uint32
)(maxV - 1));
78
}
79
81
static
inline
int
rand
(
int
maxV) {
82
return
(
int
)
RandHelper::myRandomNumberGenerator
.
randInt
((
MTRand::uint32
)(maxV - 1));
83
}
84
86
static
inline
int
rand
(
int
minV,
int
maxV) {
87
return
minV +
rand
(maxV - minV);
88
}
89
91
static
inline
SUMOReal
randNorm
(
SUMOReal
mean,
SUMOReal
variance,
MTRand
& rng =
myRandomNumberGenerator
) {
92
return
(
SUMOReal
) rng.randNorm(mean, variance);
93
}
94
96
template
<
class
T>
97
static
inline
T
98
getRandomFrom
(
const
std::vector<T>& v) {
99
assert(v.size() > 0);
100
return
v[
rand
(v.size())];
101
}
102
103
104
protected
:
106
static
MTRand
myRandomNumberGenerator
;
107
108
};
109
110
#endif
111
112
/****************************************************************************/
113
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
utils
common
RandHelper.h
Generated on Sun Jun 16 2013 07:08:23 for SUMO - Simulation of Urban MObility by
1.8.1.2