15#ifndef ARCANE_RANDOM_MERSENNE_TWISTER_H
16#define ARCANE_RANDOM_MERSENNE_TWISTER_H
20#include "arcane/utils/FatalErrorException.h"
22#include "arcane/random/RandomGlobal.h"
48 typedef UIntType result_type;
49 static const Integer word_size = w;
50 static const Integer state_size = n;
51 static const Integer shift_size = m;
52 static const Integer mask_bits = r;
53 static const UIntType parameter_a = a;
54 static const Integer output_u = u;
55 static const Integer output_s = s;
56 static const UIntType output_b = b;
57 static const Integer output_t = t;
58 static const UIntType output_c = c;
59 static const Integer output_l = l;
61 static const bool has_fixed_range =
false;
99 template<
class Generator>
122 const UIntType mask = ~0u;
124 for (i = 1; i < n; i++) {
126 x[i] = (1812433253UL * (x[i-1] ^ (x[i-1] >> (w-2))) + i) & mask;
138 {
for (
Integer i=0;i<n;i++) x[i] = state[i];}
148 template<
class Generator>
178 result_type
min()
const {
return 0; }
216 for(
Integer j = 0; j < state_size; ++j)
229 {
return !(*
this == rhs); }
244 return x[ (i + n + index) % (2*n) ];
269void MersenneTwister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::twist(
int block)
271 const UIntType upper_mask = (~0u) << r;
272 const UIntType lower_mask = ~upper_mask;
275 for(
Integer j = n; j < 2*n; j++) {
276 UIntType y = (x[j-n] & upper_mask) | (x[j-(n-1)] & lower_mask);
277 x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
279 }
else if (block == 1) {
282 for(
Integer j = 0; j < n-m; j++) {
283 UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
284 x[j] = x[j+n+m] ^ (y >> 1) ^ (y&1 ? a : 0);
288 for(
Integer j = n-m; j < n-1; j++) {
289 UIntType y = (x[j+n] & upper_mask) | (x[j+n+1] & lower_mask);
290 x[j] = x[j-(n-m)] ^ (y >> 1) ^ (y&1 ? a : 0);
293 UIntType y = (x[2*n-1] & upper_mask) | (x[0] & lower_mask);
294 x[n-1] = x[m-1] ^ (y >> 1) ^ (y&1 ? a : 0);
309inline typename MersenneTwister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::result_type
310MersenneTwister<UIntType,w,n,m,r,a,u,s,b,t,c,l,val>::operator()()
330 7,0x31b6ab00,15,0xffe50000,17, 0xa37d3c92> Mt11213b;
335 7,0x9d2c5680,15,0xefc60000,18, 3346425566U> Mt19937;
void twist(Integer block)
Réalisation de l'opération "twist" associée au Mersenne Twister. L'état du générateur est modifié.
MersenneTwister(UIntType value)
Constructeur avec initialisation du tableau de graines à partir de la valeur value....
Arcane::MersenneTwister< UInt32, 32, 351, 175, 19, 0xccab8ee7, 11, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 >::compute UInt32 compute(UInt32 index) const
MersenneTwister(It &first, It last)
Constructeur avec initialisation du tableau de graines à partir de la méthode seed(first,...
result_type min() const
min() retourne la valeur minimum possible d'une séquence.
MersenneTwister()
Constructeur avec initialisation de la graine à partir de la méthode seed()
bool operator!=(const MersenneTwister &rhs) const
Surdéfinition de l'opérateur !=.
bool operator==(const MersenneTwister &rhs) const
Surdéfinition de l'opérateur ==.
result_type max() const
max() retourne la valeur maximum possible d'une séquence.
Arcane::MersenneTwister< UInt32, 32, 351, 175, 19, 0xccab8ee7, 11, 7, 0x31b6ab00, 15, 0xffe50000, 17, 0xa37d3c92 >::seed void seed()
MersenneTwister(Generator &gen)
Constructeur avec initialisation du tableau de graines à partir du générateur gen....
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...
void seed(UIntType *state)
Initialisation du tableau de graines à partir du tableau state. state doit être un tableau de n éléme...
void seed(Generator &gen)
Initialisation du tableau de graines à partir du générateur gen. gen est une classe qui doit contenir...
static bool validation(result_type v)
Fonction de validation (je ne sais pas trop a quoi elle sert!)
result_type operator()()
Surdéfinition de l'opérateur () qui retourne la valeur pseudo aléatoire du générateur....
void seed(UIntType value)
Initialisation du tableau de graines à partir de la valeur value. Le tableau de graines de ce générat...
std::uint32_t UInt32
Type entier non signé sur 32 bits.
Int32 Integer
Type représentant un entier.