1 // -*- C++ -*- 2 /** 3 * @brief RandomGenerator implements methods to control the random generator 4 * 5 * Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca 6 * 7 * This library is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser 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 * This library 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 Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this library. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 #ifndef OPENTURNS_RANDOMGENERATOR_HXX 22 #define OPENTURNS_RANDOMGENERATOR_HXX 23 24 #include "openturns/OTprivate.hxx" 25 #include "openturns/Collection.hxx" 26 #include "openturns/Point.hxx" 27 #include "openturns/RandomGeneratorState.hxx" 28 29 BEGIN_NAMESPACE_OPENTURNS 30 31 32 33 class MersenneTwister; 34 35 /** 36 * @class RandomGenerator 37 * 38 * RandomGenerator implements methods to control the random generator 39 */ 40 41 class OT_API RandomGenerator 42 { 43 public: 44 45 typedef Collection<UnsignedInteger> UnsignedIntegerCollection; 46 47 /** Seed accessor */ 48 static void SetSeed(const UnsignedInteger seed); 49 50 /** State accessor */ 51 static void SetState(const RandomGeneratorState & state); 52 static RandomGeneratorState GetState(); 53 54 /** Generate a pseudo-random number uniformly distributed over [0, 1[ */ 55 static Scalar Generate(); 56 /** Generate a pseudo-random integer uniformly distributed over [[0,...,n-1]] */ 57 static UnsignedInteger IntegerGenerate(const UnsignedInteger n); 58 59 /** Generate a pseudo-random vector of numbers uniformly distributed over [0, 1[ */ 60 static Point Generate(const UnsignedInteger size); 61 /** Generate a pseudo-random vector of integers uniformly distributed over [[0,...,n-1]] */ 62 static UnsignedIntegerCollection IntegerGenerate(const UnsignedInteger size, const UnsignedInteger n); 63 64 private: 65 /** Default constructor */ 66 RandomGenerator(); 67 68 static Bool IsInitialized; 69 static MersenneTwister Generator; 70 71 }; /* class RandomGenerator */ 72 73 74 END_NAMESPACE_OPENTURNS 75 76 #endif /* OPENTURNS_RANDOMGENERATOR_HXX */ 77