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