1 | // SuperTux |
2 | // Copyright (C) 2018 Ingo Ruhnke <grumbel@gmail.com> |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | |
17 | #ifndef HEADER_SUPERTUX_MATH_RANDOM_HPP |
18 | #define HEADER_SUPERTUX_MATH_RANDOM_HPP |
19 | |
20 | #include <random> |
21 | |
22 | class Random |
23 | { |
24 | public: |
25 | Random(); |
26 | |
27 | /** Seed the generator */ |
28 | void seed(int v); |
29 | |
30 | /** Generate random integers between [0, INT_MAX) */ |
31 | int rand(); |
32 | |
33 | /** Generate random integers between [0, v) */ |
34 | int rand(int v); |
35 | |
36 | /** Generate random integers between [u, v) */ |
37 | int rand(int u, int v); |
38 | |
39 | /** Generate random floats between [0, v) */ |
40 | float randf(float v); |
41 | |
42 | /** Generate random floats between [u, v) */ |
43 | float randf(float u, float v); |
44 | |
45 | private: |
46 | std::mt19937 m_generator; |
47 | |
48 | private: |
49 | Random(const Random&) = delete; |
50 | Random& operator=(const Random&) = delete; |
51 | }; |
52 | |
53 | /** Use for random particle fx or whatever */ |
54 | extern Random graphicsRandom; |
55 | |
56 | /** Use for game-changing random numbers */ |
57 | extern Random gameRandom; |
58 | |
59 | #endif |
60 | |
61 | /* EOF */ |
62 | |