Arcane  v3.16.8.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
InversiveCongruential.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/* InversiveCongruential.h (C) 2000-2025 */
9/* */
10/* Ce fichier définit le patron de classe InversiveCongruential ainsi qu'une */
11/* classe associée Hellekalek1995. Il est une version adaptée du fichier */
12/* InversiveCongruential.hpp provenant de la bibliothèque BOOST */
13/*---------------------------------------------------------------------------*/
14/*---------------------------------------------------------------------------*/
15#ifndef ARCANE_CORE_RANDOM_INVERSIVECONGRUENTIAL_H
16#define ARCANE_CORE_RANDOM_INVERSIVECONGRUENTIAL_H
17/*---------------------------------------------------------------------------*/
18/*---------------------------------------------------------------------------*/
19
20#include "arcane/utils/FatalErrorException.h"
21
22#include "arcane/core/random/RandomGlobal.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane::random
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
47template<typename IntType, IntType a, IntType c, IntType m, IntType val>
49{
50 public:
51 typedef IntType result_type;
52 static const bool has_fixed_range = true;
53 static const result_type min_value = ( c == 0 ? 1 : 0 );
54 static const result_type max_value = m-1;
55 /*---------------------------------------------------------------------------*/
56 /*---------------------------------------------------------------------------*/
62 result_type min() const { return c == 0 ? 1 : 0; }
63 /*---------------------------------------------------------------------------*/
64 /*---------------------------------------------------------------------------*/
70 result_type max() const { return m-1; }
71 /*---------------------------------------------------------------------------*/
72 /*---------------------------------------------------------------------------*/
79 explicit InversiveCongruential(IntType x0 = 1)
80 : _x(x0)
81 {
82 }
83 /*---------------------------------------------------------------------------*/
84 /*---------------------------------------------------------------------------*/
90 void seed(IntType x0) { _x = x0; }
91 /*---------------------------------------------------------------------------*/
92 /*---------------------------------------------------------------------------*/
98 IntType getState() const { return _x; }
99 /*---------------------------------------------------------------------------*/
100 /*---------------------------------------------------------------------------*/
107 IntType operator()()
108 {
109 _x = apply(_x);
110 return _x;
111 }
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
121 static IntType apply(IntType x)
122 {
123 typedef utils::const_mod<IntType, m> do_mod;
124 return x = do_mod::mult_add(a,do_mod::invert(x), c);
125 }
126 /*---------------------------------------------------------------------------*/
127 /*---------------------------------------------------------------------------*/
133 bool validation(IntType x) const { return val == x; }
134 /*---------------------------------------------------------------------------*/
135 /*---------------------------------------------------------------------------*/
141 bool operator==(const InversiveCongruential& rhs) const
142 { return _x == rhs._x; }
143
144 private:
145
146 IntType _x;
147};
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
151
152typedef InversiveCongruential<Int32, 9102, 2147483647-36884165,
153 2147483647, 0> Hellekalek1995;
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158}
159
160/*---------------------------------------------------------------------------*/
161/*---------------------------------------------------------------------------*/
162
163#endif
164
result_type max() const
Retourne la valeur maximum possible d'une séquence.
result_type min() const
Retourne la valeur minimum possible d'une séquence.
IntType operator()()
Surdéfinition de l'opérateur () qui retourne la valeur pseudo aléatoire du générateur....
bool validation(IntType x) const
Fonction de validation (je ne sais pas trop a quoi elle sert!)
static IntType apply(IntType x)
Retourne la valeur pseudo aléatoire à partir de l'état x. Le membre privée _x du générateur n'est pas...
void seed(IntType x0)
Initialisation de la graine du générateur à partir de la valeur x0.
bool operator==(const InversiveCongruential &rhs) const
Surdéfinition de l'opérateur ==.
IntType getState() const
Méthode qui retourne l'état générateur.
InversiveCongruential(IntType x0=1)
Constructeur avec initialisation de la graine à partir de la valeur x0.
std::int32_t Int32
Type entier signé sur 32 bits.