MxEngine
Random.h
1 // Copyright(c) 2019 - 2020, #Momo
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met :
6 //
7 // 1. Redistributions of source code must retain the above copyright notice, this
8 // list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and /or other materials provided with the distribution.
13 //
14 // 3. Neither the name of the copyright holder nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #pragma once
30 
31 #include <random>
32 
33 namespace MxEngine
34 {
39  class Random
40  {
41  public:
42  using RandomReturnType = std::int64_t;
43 
47  using Generator = std::mersenne_twister_engine<std::uint_fast64_t, 64, 312, 156, 31,
48  0xb5026f5aa96619e9, 29,
49  0x5555555555555555, 17,
50  0x71d67fffeda60000, 37,
51  0xfff7eee000000000, 43, 6364136223846793005>;
52  private:
56  static thread_local inline Generator mersenne64;
57  public:
61  static constexpr RandomReturnType Max = std::numeric_limits<RandomReturnType>::max();
65  static constexpr RandomReturnType Min = std::numeric_limits<RandomReturnType>::min();
66 
71  static void SetSeed(Generator::result_type seed);
76  static float GetFloat();
81  static int64_t Get(int64_t lower, int64_t upper);
86  static int32_t Get(int32_t lower, int32_t upper);
91  static float Get(float lower, float upper);
92  };
93 }
static constexpr RandomReturnType Max
Definition: Random.h:61
static void SetSeed(Generator::result_type seed)
Definition: Random.cpp:43
Definition: Random.h:39
std::mersenne_twister_engine< std::uint_fast64_t, 64, 312, 156, 31, 0xb5026f5aa96619e9, 29, 0x5555555555555555, 17, 0x71d67fffeda60000, 37, 0xfff7eee000000000, 43, 6364136223846793005 > Generator
Definition: Random.h:51
static int64_t Get(int64_t lower, int64_t upper)
Definition: Random.cpp:58
Definition: Application.cpp:49
static float GetFloat()
Definition: Random.cpp:48
static constexpr RandomReturnType Min
Definition: Random.h:65