SuperTuxKart
random_generator.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2008-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef HEADER_RANDOM_GENERATOR_HPP
20 #define HEADER_RANDOM_GENERATOR_HPP
21 
22 #include <random>
23 #include <vector>
24 
33 {
34 private:
35  static unsigned int m_random_value;
36  static constexpr unsigned int default_seed = 3141591;
37 #ifdef NOT_USED_ATM
38  unsigned int m_a = 1103515245;
39  unsigned int m_c = 12345;
40 #endif
41 // static std::vector<RandomGenerator*> m_all_random_generators;
42 
43 public:
44  RandomGenerator() = default;
46  static std::mt19937& getGenerator();
47  //std::vector<int> generateAllSeeds();
49  int get(int n) {
50  std::uniform_int_distribution<int> dist(0, n - 1);
51  return dist(getGenerator());
52  }
53  static void seed(int s) {m_random_value = s;}
54 }; // RandomGenerator
55 
56 #endif // HEADER_RANDOM_GENERATOR_HPP
A random number generator.
Definition: random_generator.hpp:33
static std::mt19937 & getGenerator()
Return a reference to the thread-local generator.
Definition: random_generator.cpp:25
int get(int n)
Returns a pseudo random number between 0 and n-1 inclusive.
Definition: random_generator.hpp:49