HoverRace  2.0
Random.h
Go to the documentation of this file.
1 
2 // Random.h
3 //
4 // Copyright (c) 2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <random>
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37 namespace Util {
38 
39 class MR_DllDeclare RandSource : public std::mt19937
40 {
41  using SUPER = std::mt19937;
42 
43 public:
44  RandSource();
45 
46 public:
47  static RandSource &ForThread();
48 };
49 
58 template<class T>
59 class RandomInt
60 {
61 public:
62  RandomInt(T min, T max) :
63  dist(min, max), src(RandSource::ForThread()) { }
64 
65 public:
66  T operator()() { return dist(src); }
67 
68 private:
69  std::uniform_int_distribution<T> dist;
71 };
72 
73 } // namespace Util
74 } // namespace HoverRace
75 
76 #undef MR_DllDeclare
std::uniform_int_distribution< T > dist
Definition: Random.h:69
Ranged pseudo-random number generator.
Definition: Random.h:59
Definition: Random.h:39
RandomInt(T min, T max)
Definition: Random.h:62
#define MR_DllDeclare
Definition: Random.h:33
RandSource & src
Definition: Random.h:70
std::mt19937 SUPER
Definition: Random.h:41
Definition: Announcement.h:24
T operator()()
Definition: Random.h:66