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 29 /** 30 * Random Number Generator used throughout the game 31 * for all your randomness needs. Uses a 64-bit xorshift 32 * pseudorandom number generator. 33 */ 34 namespace RNG 35 { 36 /// Gets the seed in use. 37 uint64_t getSeed(); 38 /// Sets the seed in use. 39 void setSeed(uint64_t n); 40 /// Generates a random integer number, inclusive. 41 int generate(int min, int max); 42 /// Generates a random floating-point number. 43 double generate(double min, double max); 44 /// Get normally distributed value. 45 double boxMuller(double m = 0, double s = 1); 46 /// Generates a percentage chance. 47 bool percent(int value); 48 /// Generates a random integer number, exclusive. 49 int generateEx(int max); 50 /// Shuffles a list randomly. 51 /** 52 * Randomly changes the orders of the elements in a list. 53 * @param list The container to randomize. 54 */ 55 template <typename T> shuffle(T & list)56 void shuffle(T &list) 57 { 58 std::random_shuffle(list.begin(), list.end(), generateEx); 59 } 60 } 61 62 } 63 64 #endif 65