Arcane  v3.14.10.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-2022 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-2006 */
9/* */
10/* Ce fichier définit le patron de classe TKiss ainsi que la classe associée */
11/* Kiss. */
12/*---------------------------------------------------------------------------*/
13/*---------------------------------------------------------------------------*/
14#ifndef ARCANE_RANDOM_KISS_H
15#define ARCANE_RANDOM_KISS_H
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19#include "arcane/utils/FatalErrorException.h"
20
21#include "arcane/random/RandomGlobal.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26ARCANE_BEGIN_NAMESPACE
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31RANDOM_BEGIN_NAMESPACE
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
47template<typename UIntType, UIntType val>
48class TKiss
49{
50 public:
51 typedef UIntType result_type;
52 typedef UIntType state_type;
53 static const bool has_fixed_range = true;
54 static const result_type min_value = 0 ;
55 static const result_type max_value = 4294967295U;
56 /*---------------------------------------------------------------------------*/
57 /*---------------------------------------------------------------------------*/
63 result_type min() const { return min_value; }
64 /*---------------------------------------------------------------------------*/
65 /*---------------------------------------------------------------------------*/
71 result_type max() const { return max_value; }
72 /*---------------------------------------------------------------------------*/
73 /*---------------------------------------------------------------------------*/
80 explicit TKiss(UIntType x0 = 30903, UIntType y0 = 30903, UIntType z0 = 30903, UIntType w0 = 30903, UIntType carry0 = 0)
81 {
82 _state[0] = x0;
83 _state[1] = y0;
84 _state[2] = z0;
85 _state[3] = w0;
86 _state[4] = carry0;
87 }
88 /*---------------------------------------------------------------------------*/
89 /*---------------------------------------------------------------------------*/
96 void seed(UIntType * state)
97 { for (Integer i=0;i<5;i++) _state[i] = state[i];}
98 /*---------------------------------------------------------------------------*/
99 /*---------------------------------------------------------------------------*/
109 { for (Integer i=0;i<4;i++) _state[i] = x0;
110 _state[4] = 0;
111}
112 /*---------------------------------------------------------------------------*/
113 /*---------------------------------------------------------------------------*/
121 { _state[0] = x0; _state[1] = y0;_state[2] = z0;_state[3] = w0;_state[4] = carry0;}
122 /*---------------------------------------------------------------------------*/
123 /*---------------------------------------------------------------------------*/
131 UIntType getState(Integer i) const { return _state[i]; }
132 /*---------------------------------------------------------------------------*/
133 /*---------------------------------------------------------------------------*/
141 {
142 UIntType t;
143 _state[0] = _state[0] * 69069 + 1;
144 _state[1] ^= _state[1] << 13;
145 _state[1] ^= _state[1] >> 17;
146 _state[1] ^= _state[1] << 5;
147
148 t = (_state[3]<<1) + _state[2] + _state[4];
149 _state[4] = ((_state[2]>>2) + (_state[3]>>3) + (_state[4]>>2)) >>30;
150 _state[2]=_state[3];
151 _state[3]=t;
152 return (_state[0] + _state[1] + _state[2]);
153 }
154 /*---------------------------------------------------------------------------*/
155 /*---------------------------------------------------------------------------*/
161 bool validation(UIntType x) const { return val == x; }
162 /*---------------------------------------------------------------------------*/
163 /*---------------------------------------------------------------------------*/
169 bool operator==(const TKiss& rhs) const
170 { 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]) ; }
171
172 private:
173
174 state_type _state[5];
175
176};
177
178/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
180
181typedef TKiss<UInt32, 0> Kiss;
182
183/*---------------------------------------------------------------------------*/
184/*---------------------------------------------------------------------------*/
185
186RANDOM_END_NAMESPACE
187ARCANE_END_NAMESPACE
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192#endif
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
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:120
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:96
result_type min() const
Retourne la valeur minimum possible d'une séquence.
Definition TKiss.h:63
bool operator==(const TKiss &rhs) const
Surdéfinition de l'opérateur ==.
Definition TKiss.h:169
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:80
result_type max() const
Retourne la valeur maximum possible d'une séquence.
Definition TKiss.h:71
bool validation(UIntType x) const
Fonction de validation (je ne sais pas trop a quoi elle sert!)
Definition TKiss.h:161
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:140
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:131
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:108