mn_random_lfsr.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_LFSR_H_
21 #define _MINLIB_RANDOM_LFSR_H_
22 
23 #include "mn_random.hpp"
24 
25 namespace mn {
36  class basic_random_lfsr : public IPseudoRandomUtil<unsigned int> {
37  public:
38  basic_random_lfsr(unsigned int startSeed = 0xFEABDC72, unsigned int polyMask = 0xA1B3C6DF)
39  : IPseudoRandomUtil<unsigned int>(startSeed), m_uiPolyMask(0xA1B3C6DF) { }
40 
46  virtual unsigned char rand8() override;
52  virtual unsigned short rand16() override;
58  virtual unsigned int rand32() override;
59 
65  unsigned int get_polymask() { return m_uiPolyMask; }
71  void set_polymask(unsigned int mask) { m_uiPolyMask = mask; }
78  void set_seed(unsigned int seed, unsigned int mask) {
79  m_startSeed = seed; m_uiPolyMask = mask;
80  }
81  private:
82  unsigned int m_uiPolyMask;
83  };
84 
85 }
86 
87 #endif
88 
An Intarface for all randoms classes in this library.
Definition: mn_random.hpp:32
seed_t m_startSeed
Definition: mn_random.hpp:94
Pseudro-Random Number Generator based on a 32-bit linear-feedback shift register.
Definition: mn_random_lfsr.hpp:36
unsigned int get_polymask()
Get the polymask.
Definition: mn_random_lfsr.hpp:65
void set_polymask(unsigned int mask)
Set the a new polymask.
Definition: mn_random_lfsr.hpp:71
virtual unsigned char rand8() override
Get a random unsigned char number.
Definition: mn_random_lfsr.cpp:29
void set_seed(unsigned int seed, unsigned int mask)
Set a new seed, with new polymask.
Definition: mn_random_lfsr.hpp:78
basic_random_lfsr(unsigned int startSeed=0xFEABDC72, unsigned int polyMask=0xA1B3C6DF)
Definition: mn_random_lfsr.hpp:38
virtual unsigned short rand16() override
Get a random unsigned short number.
Definition: mn_random_lfsr.cpp:34
unsigned int m_uiPolyMask
Definition: mn_random_lfsr.hpp:82
virtual unsigned int rand32() override
Get a random unsigned int number.
Definition: mn_random_lfsr.cpp:44
Definition: mn_allocator_typetraits.hpp:25