SUMO - Simulation of Urban MObility
 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-sim.org/
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>
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() {
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) {
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:
107 
108 };
109 
110 #endif
111 
112 /****************************************************************************/
113