15#ifndef ARCANE_CORE_RANDOM_MERSENNETWISTER_H
16#define ARCANE_CORE_RANDOM_MERSENNETWISTER_H
20#include "arcane/utils/FatalErrorException.h"
22#include "arcane/core/random/RandomGlobal.h"
27namespace Arcane::random
50 typedef UIntType result_type;
51 static const Integer word_size = w;
52 static const Integer state_size = n;
53 static const Integer shift_size = m;
54 static const Integer mask_bits = r;
55 static const UIntType parameter_a = a;
56 static const Integer output_u = u;
57 static const Integer output_s = s;
58 static const UIntType output_b = b;
59 static const Integer output_t = t;
60 static const UIntType output_c = c;
61 static const Integer output_l = l;
63 static const bool has_fixed_range =
false;
101 template<
class Generator>
124 const UIntType mask = ~0u;
126 for (i = 1; i < n; i++) {
128 x[i] = (1812433253UL * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
140 {
for (
Integer i=0;i<n;i++) x[i] = state[i];}
150 template<
class Generator>
180 result_type
min()
const {
return 0; }
218 for(
Integer j = 0; j < state_size; ++j)
231 {
return !(*
this == rhs); }
246 return x[ (i + n + index) % (2*n) ];
271void MersenneTwister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::twist(
int block)
273 const UIntType upper_mask = (~0u) << r;
274 const UIntType lower_mask = ~upper_mask;
277 for(
Integer j = n; j < 2*n; j++) {
278 UIntType y = (x[j-n] & upper_mask) | (x[j-(n-1)] & lower_mask);
279 x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
281 }
else if (block == 1) {
284 for(
Integer j = 0; j < n-m; j++) {
285 UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
286 x[j] = x[j+n+m] ^ (y >> 1) ^ (y&1 ? a : 0);
290 for(
Integer j = n-m; j < n-1; j++) {
291 UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
292 x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
295 UIntType y = (x[2*n-1] & upper_mask) | (x[0] & lower_mask);
296 x[n-1] = x[m-1] ^ (y >> 1) ^ (y&1 ? a : 0);
311inline typename MersenneTwister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::result_type
312MersenneTwister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::operator()()
332 7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> Mt11213b;
337 7,0x9d2c5680,15,0xefc60000,18, 3346425566U> Mt19937;
Patron de classe MersenneTwister.
static bool validation(result_type v)
Fonction de validation (je ne sais pas trop a quoi elle sert!)
MersenneTwister()
Constructeur avec initialisation de la graine à partir de la méthode seed()
MersenneTwister(UIntType value)
Constructeur avec initialisation du tableau de graines à partir de la valeur value....
bool operator!=(const MersenneTwister &rhs) const
Surdéfinition de l'opérateur !=.
void seed(UIntType *state)
Initialisation du tableau de graines à partir du tableau state. state doit être un tableau de n éléme...
void seed(UIntType value)
Initialisation du tableau de graines à partir de la valeur value. Le tableau de graines de ce générat...
MersenneTwister(Generator &gen)
Constructeur avec initialisation du tableau de graines à partir du générateur gen....
result_type max() const
max() retourne la valeur maximum possible d'une séquence.
void seed(Generator &gen)
Initialisation du tableau de graines à partir du générateur gen. gen est une classe qui doit contenir...
UIntType getState(Integer j)
Méthode qui retourne l'état du générateur pour l'index j. L'état complet du générateur est donnée par...
bool operator==(const MersenneTwister &rhs) const
Surdéfinition de l'opérateur ==.
void twist(Integer block)
Réalisation de l'opération "twist" associée au Mersenne Twister. L'état du générateur est modifié.
UIntType compute(UIntType index) const
Méthode privée qui retourne l'état du générateur pour l'index index.
MersenneTwister(It &first, It last)
Constructeur avec initialisation du tableau de graines à partir de la méthode seed(first,...
void seed()
Initialisation du tableau de graines. L'appel à la méthode seed(5489) est réalisé.
result_type operator()()
Surdéfinition de l'opérateur () qui retourne la valeur pseudo aléatoire du générateur....
result_type min() const
min() retourne la valeur minimum possible d'une séquence.
std::uint32_t UInt32
Type entier non signé sur 32 bits.
Int32 Integer
Type représentant un entier.