OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
RNG.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_RNG_H
20 #define OPENXCOM_RNG_H
21 
22 #include <algorithm>
23 #define __STDC_LIMIT_MACROS
24 #include <stdint.h>
25 
26 namespace OpenXcom
27 {
28 
34 namespace RNG
35 {
37  uint64_t getSeed();
39  void setSeed(uint64_t n);
41  int generate(int min, int max);
43  double generate(double min, double max);
45  double boxMuller(double m = 0, double s = 1);
47  bool percent(int value);
49  int generateEx(int max);
51 
55  template <typename T>
56  void shuffle(T &list)
57  {
58  std::random_shuffle(list.begin(), list.end(), generateEx);
59  }
60 }
61 
62 }
63 
64 #endif
uint64_t getSeed()
Returns the current seed in use by the generator.
Definition: RNG.cpp:54
void setSeed(uint64_t n)
Changes the current seed in use by the generator.
Definition: RNG.cpp:63
int generateEx(int max)
Generates a random positive integer up to a number.
Definition: RNG.cpp:143
void shuffle(T &list)
Shuffles a list randomly.
Definition: RNG.h:56
int generate(int min, int max)
Generates a random integer number within a certain range.
Definition: RNG.cpp:74
double boxMuller(double m, double s)
Normal random variate generator.
Definition: RNG.cpp:98
bool percent(int value)
Generates a random percent chance of an event occuring, and returns the result.
Definition: RNG.cpp:133