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.cpp
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-2012 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
22
23
// ===========================================================================
24
// included modules
25
// ===========================================================================
26
#ifdef _MSC_VER
27
#include <
windows_config.h
>
28
#else
29
#include <
config.h
>
30
#endif
31
32
#include <
utils/options/OptionsCont.h
>
33
#include <
utils/common/SysUtils.h
>
34
#include "
RandHelper.h
"
35
#include <ctime>
36
#include <cmath>
37
38
#ifdef CHECK_MEMORY_LEAKS
39
#include <
foreign/nvwa/debug_new.h
>
40
#endif // CHECK_MEMORY_LEAKS
41
42
43
// ===========================================================================
44
// static member variables
45
// ===========================================================================
46
MTRand
RandHelper::myRandomNumberGenerator
;
47
48
49
// ===========================================================================
50
// member method definitions
51
// ===========================================================================
52
void
53
RandHelper::insertRandOptions
() {
54
OptionsCont
& oc =
OptionsCont::getOptions
();
55
// registers random number options
56
oc.
addOptionSubTopic
(
"Random Number"
);
57
58
oc.
doRegister
(
"random"
,
new
Option_Bool
(
false
));
59
oc.
addSynonyme
(
"random"
,
"abs-rand"
,
true
);
60
oc.
addDescription
(
"random"
,
"Random Number"
,
"Initialises the random number generator with the current system time"
);
61
62
oc.
doRegister
(
"seed"
,
new
Option_Integer
(23423));
63
oc.
addSynonyme
(
"seed"
,
"srand"
,
true
);
64
oc.
addDescription
(
"seed"
,
"Random Number"
,
"Initialises the random number generator with the given value"
);
65
}
66
67
void
68
RandHelper::initRandGlobal
(
MTRand
* which) {
69
OptionsCont
& oc =
OptionsCont::getOptions
();
70
if
(which == 0) {
71
which = &
myRandomNumberGenerator
;
72
}
73
if
(oc.
getBool
(
"random"
)) {
74
#ifdef _MSC_VER
75
long
s =
myRandomNumberGenerator
.
hash
(time(NULL), clock()) + SysUtils::getWindowsTicks();
76
unsigned
int
s2 = (
unsigned
int
)(s & 0xffff) ^ (s >> 16);
77
if
(s2 < 0) {
78
s2 *= -1;
79
}
80
which->
seed
(s2);
81
#else
82
which->
seed
();
83
#endif
84
}
else
{
85
which->
seed
(oc.
getInt
(
"seed"
));
86
}
87
}
88
89
90
/****************************************************************************/
91
build
buildd
sumo-0.16.0~dfsg
src
utils
common
RandHelper.cpp
Generated on Tue Apr 16 2013 01:32:20 for SUMO - Simulation of Urban MObility by
1.8.3.1