13#ifndef ARCANE_RANDOM_UNIFORMONINT_H
14#define ARCANE_RANDOM_UNIFORMONINT_H
18#include "arcane/utils/FatalErrorException.h"
20#include "arcane/random/UniformSmallInt.h"
58template<
class UniformRandomNumberGenerator,
class IntType =
int>
63 typedef IntType result_type;
64 static const bool has_fixed_range =
false;
67 : _rng(
rng), _min(min), _max(max), _range(_max - _min),
68 _bmin(_rng.min()), _brange(_rng.max() - _bmin)
70 if(utils::equal_signed_unsigned(_brange, _range))
71 _range_comparison = 0;
72 else if(utils::lessthan_signed_unsigned(_brange, _range))
73 _range_comparison = -1;
75 _range_comparison = 1;
77 result_type operator()();
78 result_type min()
const {
return _min; }
79 result_type max()
const {
return _max; }
81 typedef typename base_type::result_type base_result;
83 result_type _min, _max, _range;
84 base_result _bmin, _brange;
85 int _range_comparison;
88template<
class UniformRandomNumberGenerator,
class IntType>
91 if(_range_comparison == 0) {
94 return static_cast<result_type
>(_rng() - _bmin) + _min;
95 }
else if(_range_comparison < 0) {
101 if(_range == std::numeric_limits<result_type>::max()) {
102 limit = _range/(
static_cast<result_type
>(_brange)+1);
103 if(_range %
static_cast<result_type
>(_brange)+1 ==
static_cast<result_type
>(_brange))
106 limit = (_range+1)/(
static_cast<result_type
>(_brange)+1);
110 result_type result = 0;
111 result_type
mult = 1;
112 while(mult <= limit) {
113 result += (_rng() - _bmin) * mult;
114 mult *=
static_cast<result_type
>(_brange)+1;
120 result += UniformInt<base_type,result_type>(_rng, 0, _range/mult)() * mult;
122 return result + _min;
125 if(_brange / _range > 4 ) {
128 return UniformSmallInt<base_type,result_type>(_rng, _min, _max)();
132 base_result result = _rng() - _bmin;
135 if(result <=
static_cast<base_result
>(_range))
136 return result + _min;
Lecteur des fichiers de maillage via la bibliothèque LIMA.
void mult(ArrayView< T > lhs, ConstArrayView< T > copy_array)
Multiplie terme à terme les éléments de l'instance par les éléments du tableau copy_array.