mn_random.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2021 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 
19 
20 #ifndef _MINLIB_RANDOM_H_
21 #define _MINLIB_RANDOM_H_
22 
23 #include "../mn_limits.hpp"
24 
25 namespace mn {
31  template <typename TSEEDTYPE>
33  protected:
37  union convers {
38  unsigned int g32;
39  unsigned char g[4];
40  unsigned short g16[2];
41 
42  };
43  public:
44  using seed_t = TSEEDTYPE;
45  using result_type = TSEEDTYPE;
46 
53  : m_startSeed(startSeed) { }
54 
60  virtual unsigned char rand8() = 0;
66  virtual unsigned short rand16() = 0;
72  virtual unsigned int rand32() = 0;
73 
79  virtual seed_t get_seed() { return m_startSeed; }
85  virtual void set_seed(seed_t seed) { m_startSeed = seed; }
86 
87  result_type operator () (bool b = true) const noexcept {
88  return rand32();
89  }
90 
93  protected:
95  };
96 }
97 
98 
99 #endif
An Intarface for all randoms classes in this library.
Definition: mn_random.hpp:32
result_type operator()(bool b=true) const noexcept
Definition: mn_random.hpp:87
virtual void set_seed(seed_t seed)
Set the a new seed.
Definition: mn_random.hpp:85
virtual seed_t get_seed()
Get the current used Seed.
Definition: mn_random.hpp:79
IPseudoRandomUtil(seed_t startSeed)
Construct a new IPseudoRandomUtil object.
Definition: mn_random.hpp:52
unsigned char g[4]
Definition: mn_random.hpp:39
seed_t m_startSeed
Definition: mn_random.hpp:94
virtual unsigned short rand16()=0
Get a random unsigned short number.
virtual unsigned char rand8()=0
Get a random unsigned char number.
TSEEDTYPE result_type
Definition: mn_random.hpp:45
result_type min()
Definition: mn_random.hpp:91
unsigned int g32
Definition: mn_random.hpp:38
virtual unsigned int rand32()=0
Get a random unsigned int number.
result_type max()
Definition: mn_random.hpp:92
TSEEDTYPE seed_t
Definition: mn_random.hpp:44
unsigned short g16[2]
Definition: mn_random.hpp:40
Union for type convertion.
Definition: mn_random.hpp:37
static constexpr value_type max()
Definition: mn_limits.hpp:63
static constexpr value_type min()
Definition: mn_limits.hpp:62
Definition: mn_allocator_typetraits.hpp:25