Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
LinearCongruential.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/* LinearCongruential.h (C) 2000-2015 */
9/* */
10/* Randomiser 'LinearCongruential'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_RANDOM_LINEARCONGRUENTIAL_H
14#define ARCANE_RANDOM_LINEARCONGRUENTIAL_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/TraceInfo.h"
20#include "arcane/utils/String.h"
21
22#include "arcane/random/RandomGlobal.h"
23#include "arcane/random/ConstMod.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28ARCANE_BEGIN_NAMESPACE
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33RANDOM_BEGIN_NAMESPACE
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
48template<typename IntType, IntType a, IntType c, IntType m, IntType val>
50{
51 public:
52 typedef IntType result_type;
53 static const bool has_fixed_range = true;
54 static const result_type min_value = ( c == 0 ? 1 : 0 );
55 static const result_type max_value = m-1;
56 static const IntType multiplier = a;
57 static const IntType increment = c;
58 static const IntType modulus = m;
59
60 result_type min() const { return c == 0 ? 1 : 0; }
61 result_type max() const { return m-1; }
62 explicit LinearCongruential(IntType x0 = 1)
63 : _x(x0)
64 {
65#ifdef ARCANE_CHECK
66 checkSeed(_x);
67#endif
68 }
69 // compiler-generated copy constructor and assignment operator are fine
70 void seed(IntType x0)
71 {
72 _x = x0;
73#ifdef ARCANE_CHECK
74 checkSeed(_x);
75#endif
76 }
77 IntType getState() const { return _x; }
78 IntType operator()()
79 {
80 _x = apply(_x);
81 return _x;
82 }
83 static IntType apply(IntType x)
84 {
86 }
87 bool validation(IntType x) const { return val == x; }
88 bool operator==(const LinearCongruential& rhs) const
89 { return _x == rhs._x; }
90
91 inline void checkSeed(IntType x)
92 {
93 if (_x<min() || _x>=max())
94 throw FatalErrorException(A_FUNCINFO,String::format("Invalid seed v={0} min={1} max={2}",x,min(),max()));
95 }
96
97 private:
98
99 IntType _x;
100};
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111RANDOM_END_NAMESPACE
112ARCANE_END_NAMESPACE
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117#endif
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
compile-time configurable linear congruential generator.
Exception lorsqu'une erreur fatale est survenue.