Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TMrg32k3a.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Mrg32k3a.h (C) 2000-2025 */
9/* */
10/* Ce fichier définit le patron de classe TMrg32k3a ainsi que la classe */
11/* associée Mrg32k3a. */
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_CORE_RANDOM_MRG32K3A_H
14#define ARCANE_CORE_RANDOM_MRG32K3A_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/FatalErrorException.h"
19
20#include "arcane/core/random/RandomGlobal.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::random
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
48template<typename RealType, Int32 val>
50{
51 public:
52 typedef RealType result_type;
53 typedef RealType state_type;
54 static const bool has_fixed_range = true;
55 static const Int32 min_value=0;
56 static const Int32 max_value=1;
57 /*---------------------------------------------------------------------------*/
58 /*---------------------------------------------------------------------------*/
65 explicit TMrg32k3a(Int32 x0 = 1)
66 {
67 seed(x0);
68 }
69 /*---------------------------------------------------------------------------*/
70 /*---------------------------------------------------------------------------*/
77 explicit TMrg32k3a(state_type *state)
78 {
79 for(Integer i=0;i<6;i++)
80 _state[i] = state[i];
81 }
82 /*---------------------------------------------------------------------------*/
83 /*---------------------------------------------------------------------------*/
90 void seed(Int32 x0) {
91 x0 = (x0 | 1);
92 _state[0] = (state_type) x0;
93 _state[1] = _state[0];
94 _state[2] = _state[1];
95 _state[3] = _state[2];
96 _state[4] = _state[3];
97 _state[5] = _state[4];
98}
99 /*---------------------------------------------------------------------------*/
100 /*---------------------------------------------------------------------------*/
108 RealType getState(Integer i) const { return _state[i]; }
109 /*---------------------------------------------------------------------------*/
110 /*---------------------------------------------------------------------------*/
117 RealType operator()()
118 {
119 RealType _x;
120 _x = apply(_state);
121 return _x;
122 }
123 /*---------------------------------------------------------------------------*/
124 /*---------------------------------------------------------------------------*/
131 static RealType apply(state_type* state)
132 {
133 long k;
134 Real p;
135 p = 1403580.0*state[1] - 810728.0*state[0];
136 k = static_cast<long>(p/4294967087.0); p-=k*4294967087.0; if (p <0.0) p+=4294967087.0;
137 state[0] = state[1]; state[1]=state[2]; state[2]=p;
138
139 p=527612.0*state[5] - 1370589.0*state[3];
140 k=static_cast<long>(p/4294944443.0); p-= k*4294944443.0; if(p<0.0) p+=4294944443.0;
141 state[3] = state[4]; state[4]=state[5]; state[5]=p;
142
143 if(state[2] <= state[5]) return ((state[2]-state[5]+4294967087.0)/4294967087.0);
144 else return ((state[2]-state[5]) / 4294967087.0);
145 }
146 /*---------------------------------------------------------------------------*/
147 /*---------------------------------------------------------------------------*/
153 result_type min() const { return static_cast<result_type>(min_value); }
154 /*---------------------------------------------------------------------------*/
155 /*---------------------------------------------------------------------------*/
161 result_type max() const { return static_cast<result_type>(max_value); }
162 /*---------------------------------------------------------------------------*/
163 /*---------------------------------------------------------------------------*/
169 bool validation(RealType x) const { return val == x; }
170 /*---------------------------------------------------------------------------*/
171 /*---------------------------------------------------------------------------*/
177 bool operator==(const TMrg32k3a& rhs) const
178 { return (_state[0] == rhs._state[0]) && (_state[1] == rhs._state[1]) && (_state[2] == rhs._state[2]) && (_state[3] == rhs._state[3]) && (_state[4] == rhs._state[4]) && (_state[5] == rhs._state[5]) ; }
179
180 private:
181
182 state_type _state[6];
183};
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188typedef TMrg32k3a<Real,0> Mrg32k3a;
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193}
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198#endif
bool operator==(const TMrg32k3a &rhs) const
Surdéfinition de l'opérateur ==.
Definition TMrg32k3a.h:177
static RealType apply(state_type *state)
Retourne la valeur pseudo aléatoire à partir de l'état state. L'état du générateur state doit être co...
Definition TMrg32k3a.h:131
result_type max() const
Retourne la valeur maximum possible d'une séquence.
Definition TMrg32k3a.h:161
result_type min() const
Retourne la valeur minimum possible d'une séquence.
Definition TMrg32k3a.h:153
RealType getState(Integer i) const
Méthode qui retourne l'état du générateur pour l'index i. L'état complet du générateur est donnée par...
Definition TMrg32k3a.h:108
TMrg32k3a(state_type *state)
Constructeur avec initialisation du tableau de graines à partir du tableau state. state doit être un ...
Definition TMrg32k3a.h:77
void seed(Int32 x0)
Initialisation du tableau de graines à partir de la valeur x0. Le tableau de graines de ce générateur...
Definition TMrg32k3a.h:90
TMrg32k3a(Int32 x0=1)
Constructeur avec initialisation du tableau de graines à partir de la valeur x0. L'appel à la méthode...
Definition TMrg32k3a.h:65
bool validation(RealType x) const
Fonction de validation (je ne sais pas trop a quoi elle sert!)
Definition TMrg32k3a.h:169
RealType operator()()
Surdéfinition de l'opérateur () qui retourne la valeur pseudo aléatoire du générateur....
Definition TMrg32k3a.h:117
Int32 Integer
Type représentant un entier.
double Real
Type représentant un réel.
std::int32_t Int32
Type entier signé sur 32 bits.