OpenXcom  1.0
Open-source clone of the original X-Com
RNG.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <algorithm>
21 #define __STDC_LIMIT_MACROS
22 #include <stdint.h>
23 
24 namespace OpenXcom
25 {
26 
32 namespace RNG
33 {
35  uint64_t getSeed();
37  void setSeed(uint64_t n);
39  int generate(int min, int max);
41  double generate(double min, double max);
43  int seedless(int min, int 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 }
uint64_t getSeed()
Returns the current seed in use by the generator.
Definition: RNG.cpp:58
void setSeed(uint64_t n)
Changes the current seed in use by the generator.
Definition: RNG.cpp:67
int generateEx(int max)
Generates a random positive integer up to a number.
Definition: RNG.cpp:160
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:78
double boxMuller(double m, double s)
Normal random variate generator.
Definition: RNG.cpp:115
int seedless(int min, int max)
Generates a random integer number within a certain range.
Definition: RNG.cpp:103
bool percent(int value)
Generates a random percent chance of an event occurring, and returns the result.
Definition: RNG.cpp:150
Definition: BaseInfoState.cpp:40