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.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 #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 <vector>
36 
37 
38 // ===========================================================================
39 // class declarations
40 // ===========================================================================
41 class OptionsCont;
42 
43 
44 // ===========================================================================
45 // class definitions
46 // ===========================================================================
51 class RandHelper {
52 public:
54  static void insertRandOptions();
55 
57  static void initRandGlobal();
58 
60  static inline SUMOReal rand() {
62  }
63 
65  static inline SUMOReal rand(SUMOReal maxV) {
66  return maxV * rand();
67  }
68 
70  static inline SUMOReal rand(SUMOReal minV, SUMOReal maxV) {
71  return minV + (maxV - minV) * rand();
72  }
73 
75  static inline size_t rand(size_t maxV) {
76  return (size_t) RandHelper::myRandomNumberGenerator.randInt((MTRand::uint32)(maxV - 1));
77  }
78 
80  static inline int rand(int maxV) {
82  }
83 
85  static inline int rand(int minV, int maxV) {
86  return minV + rand(maxV - minV);
87  }
88 
90  static inline SUMOReal randNorm(SUMOReal mean, SUMOReal variance) {
91  return (SUMOReal) RandHelper::myRandomNumberGenerator.randNorm(mean, variance);
92  }
93 
95  template<class T>
96  static inline T
97  getRandomFrom(const std::vector<T> &v) {
98  assert(v.size() > 0);
99  return v[rand(v.size())];
100  }
101 
102 protected:
105 
106 };
107 
108 #endif
109 
110 /****************************************************************************/
111