hx3d  1
2D/3D Simple Game Framework
random.hpp
1 /*
2  Random functions.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #ifndef HX3D_MATH_RANDOM
22 #define HX3D_MATH_RANDOM
23 
24 #include <functional>
25 #include <vector>
26 #include <map>
27 
28 namespace hx3d {
29 namespace math {
30 
53 public:
55 
63  void define(int i, int weight, std::function<void()> f);
64 
70  int random();
71 
72 private:
73  std::vector<int> _vec;
74  std::map<int, int> _weights;
75  std::map<int, std::function<void()>> _map;
76 
77  int get_number(int gen);
78  int total_count();
79 };
80 
86 float randfloat();
87 
96 int random(int min, int max);
97 
103 bool flip_coin();
104 
105 } /* math */
106 } /* hx3d */
107 
108 #endif
hx3d framework namespace
Definition: audio.hpp:26
float randfloat()
Generate a random float between 0.0 and 1.0.
Definition: random.cpp:70
int random()
Choose a random number and execute the callback.
Definition: random.cpp:42
Weighted random generator with callbacks.
Definition: random.hpp:52
void define(int i, int weight, std::function< void()> f)
Define a value with a weight and a callback.
Definition: random.cpp:32
bool flip_coin()
Generate a random boolean.
Definition: random.cpp:78