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 #include "math/random.hpp"
18
19 #include <limits>
20
21 Random graphicsRandom;
22 Random gameRandom;
23
Random()24 Random::Random() :
25 m_generator()
26 {
27 }
28
29 void
seed(int v)30 Random::seed(int v)
31 {
32 m_generator.seed(v);
33 }
34
35 int
rand()36 Random::rand()
37 {
38 std::uniform_int_distribution<int> dist(0, std::numeric_limits<int>::max() - 1);
39 return dist(m_generator);
40 }
41
42 int
rand(int v)43 Random::rand(int v)
44 {
45 std::uniform_int_distribution<int> dist(0, v - 1);
46 return dist(m_generator);
47 }
48
49 int
rand(int u,int v)50 Random::rand(int u, int v)
51 {
52 std::uniform_int_distribution<int> dist(u, v - 1);
53 return dist(m_generator);
54 }
55
56 float
randf(float v)57 Random::randf(float v)
58 {
59 std::uniform_real_distribution<float> dist(0.0f, v);
60 return dist(m_generator);
61 }
62
63 float
randf(float u,float v)64 Random::randf(float u, float v)
65 {
66 std::uniform_real_distribution<float> dist(u, v);
67 return dist(m_generator);
68 }
69
70 /* EOF */
71