Antares Simulator
Power System Simulator
mersenne-twister.h
1 /*
2 ** Copyright 2007-2025, RTE (https://www.rte-france.com)
3 ** See AUTHORS.txt
4 ** SPDX-License-Identifier: MPL-2.0
5 ** This file is part of Antares-Simulator,
6 ** Adequacy and Performance assessment for interconnected energy networks.
7 **
8 ** Antares_Simulator is free software: you can redistribute it and/or modify
9 ** it under the terms of the Mozilla Public Licence 2.0 as published by
10 ** the Mozilla Foundation, either version 2 of the License, or
11 ** (at your option) any later version.
12 **
13 ** Antares_Simulator is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** Mozilla Public Licence 2.0 for more details.
17 **
18 ** You should have received a copy of the Mozilla Public Licence 2.0
19 ** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20 */
21 #ifndef __LIB_ANTARES_RANDOM_MERSENNE_H__
22 #define __LIB_ANTARES_RANDOM_MERSENNE_H__
23 
24 #include <yuni/yuni.h>
25 #include <yuni/core/math/random/distribution.h>
26 
27 namespace Antares
28 {
40 class MersenneTwister final
41 {
42 public:
43  // Name of the distribution
44  static const char* Name()
45  {
46  return "Mersenne Twister random numbers";
47  }
48 
50  using Value = double;
51 
52  enum
53  {
55  defaultSeed = 5489,
56  };
57 
58 public:
60 
61 
68 
70 
71  void reset();
74  void reset(uint seed);
76 
78 
79 
85  Value next() const;
87 
89 
90  static Value min();
93  static Value max();
95 
96  Value operator()();
97 
98 private:
99  enum
100  {
101  periodN = 624,
102  periodM = 397,
103  };
104 
106  mutable uint32_t mt[periodN];
107  //
108  mutable int32_t mti;
109 
110 }; // class MersenneTwister
111 
112 } // namespace Antares
113 
114 #endif // __LIB_ANTARES_RANDOM_MERSENNE_H__
MersenneTwister Pseudo random number generator.
Definition: mersenne-twister.h:41
double Value
Type of a single random.
Definition: mersenne-twister.h:50
void reset()
Reset the generator.
Definition: mersenne-twister.cpp:126
Value next() const
Generate a new random number.
Definition: mersenne-twister.cpp:71
static Value min()
Lower bound.
Definition: mersenne-twister.cpp:116
static Value max()
Upper bound.
Definition: mersenne-twister.cpp:121
@ defaultSeed
A default seed.
Definition: mersenne-twister.h:55
~MersenneTwister()
Destructor.
Definition: mersenne-twister.cpp:50
MersenneTwister()
Default constructor.
Definition: mersenne-twister.cpp:45