Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TKiss.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/* TKiss.h (C) 2000-2025 */
9/* */
10/* Ce fichier définit le patron de classe TKiss ainsi que la classe associée */
11/* Kiss. */
12/*---------------------------------------------------------------------------*/
13/*---------------------------------------------------------------------------*/
14#ifndef ARCANE_CORE_RANDOM_TKISS_H
15#define ARCANE_CORE_RANDOM_TKISS_H
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include "arcane/utils/FatalErrorException.h"
20
21#include "arcane/core/random/RandomGlobal.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::random
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
40template<typename UIntType, UIntType val>
41class TKiss
42{
43 public:
44 typedef UIntType result_type;
45 typedef UIntType state_type;
46 static const bool has_fixed_range = true;
47 static const result_type min_value = 0 ;
48 static const result_type max_value = 4294967295U;
49 /*---------------------------------------------------------------------------*/
50 /*---------------------------------------------------------------------------*/
56 result_type min() const { return min_value; }
57 /*---------------------------------------------------------------------------*/
58 /*---------------------------------------------------------------------------*/
64 result_type max() const { return max_value; }
65 /*---------------------------------------------------------------------------*/
66 /*---------------------------------------------------------------------------*/
73 explicit TKiss(UIntType x0 = 30903, UIntType y0 = 30903, UIntType z0 = 30903, UIntType w0 = 30903, UIntType carry0 = 0)
74 {
75 _state[0] = x0;
76 _state[1] = y0;
77 _state[2] = z0;
78 _state[3] = w0;
79 _state[4] = carry0;
80 }
81 /*---------------------------------------------------------------------------*/
82 /*---------------------------------------------------------------------------*/
89 void seed(UIntType * state)
90 { for (Integer i=0;i<5;i++) _state[i] = state[i];}
91 /*---------------------------------------------------------------------------*/
92 /*---------------------------------------------------------------------------*/
101 void seed(UIntType x0)
102 { for (Integer i=0;i<4;i++) _state[i] = x0;
103 _state[4] = 0;
104}
105 /*---------------------------------------------------------------------------*/
106 /*---------------------------------------------------------------------------*/
113 void seed(UIntType x0,UIntType y0,UIntType z0,UIntType w0,UIntType carry0)
114 { _state[0] = x0; _state[1] = y0;_state[2] = z0;_state[3] = w0;_state[4] = carry0;}
115 /*---------------------------------------------------------------------------*/
116 /*---------------------------------------------------------------------------*/
124 UIntType getState(Integer i) const { return _state[i]; }
125 /*---------------------------------------------------------------------------*/
126 /*---------------------------------------------------------------------------*/
133 UIntType operator()()
134 {
135 UIntType t;
136 _state[0] = _state[0] * 69069 + 1;
137 _state[1] ^= _state[1] << 13;
138 _state[1] ^= _state[1] >> 17;
139 _state[1] ^= _state[1] << 5;
140
141 t = (_state[3]<<1) + _state[2] + _state[4];
142 _state[4] = ((_state[2]>>2) + (_state[3]>>3) + (_state[4]>>2)) >>30;
143 _state[2]=_state[3];
144 _state[3]=t;
145 return (_state[0] + _state[1] + _state[2]);
146 }
147 /*---------------------------------------------------------------------------*/
148 /*---------------------------------------------------------------------------*/
154 bool validation(UIntType x) const { return val == x; }
155 /*---------------------------------------------------------------------------*/
156 /*---------------------------------------------------------------------------*/
162 bool operator==(const TKiss& rhs) const
163 { 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]) ; }
164
165 private:
166
167 state_type _state[5];
168
169};
170
171/*---------------------------------------------------------------------------*/
172/*---------------------------------------------------------------------------*/
173
174typedef TKiss<UInt32, 0> Kiss;
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179}
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184#endif
result_type min() const
Retourne la valeur minimum possible d'une séquence.
Definition TKiss.h:56
void seed(UIntType x0)
Initialisation du tableau de graines à partir de la valeur x0. Le tableau de graines de ce générate...
Definition TKiss.h:101
UIntType getState(Integer i) const
Méthode qui retourne la composante i del'état du générateur. L'état complet du générateur est donnée ...
Definition TKiss.h:124
void seed(UIntType x0, UIntType y0, UIntType z0, UIntType w0, UIntType carry0)
Initialisation du tableau de graines à partir des valeurs des arguments.
Definition TKiss.h:113
UIntType operator()()
Surdéfinition de l'opérateur () qui retourne la valeur pseudo aléatoire. L'état du générateur est mod...
Definition TKiss.h:133
void seed(UIntType *state)
Initialisation du tableau de graines à partir de l'état state. L'état du générateur state doit être c...
Definition TKiss.h:89
TKiss(UIntType x0=30903, UIntType y0=30903, UIntType z0=30903, UIntType w0=30903, UIntType carry0=0)
Constructeur avec initialisation du tableau de graines à partir des valeurs des arguments.
Definition TKiss.h:73
result_type max() const
Retourne la valeur maximum possible d'une séquence.
Definition TKiss.h:64
bool validation(UIntType x) const
Fonction de validation (je ne sais pas trop a quoi elle sert!)
Definition TKiss.h:154
bool operator==(const TKiss &rhs) const
Surdéfinition de l'opérateur ==.
Definition TKiss.h:162
Int32 Integer
Type représentant un entier.