13#ifndef ARCANE_CORE_RANDOM_UNIFORMONSMALLINT_H
14#define ARCANE_CORE_RANDOM_UNIFORMONSMALLINT_H
18#include "arcane/utils/FatalErrorException.h"
20#include "arcane/core/random/NormalDistribution.h"
54template<
class UniformRandomNumberGenerator,
class IntType =
int>
58 typedef UniformRandomNumberGenerator base_type;
59 typedef IntType result_type;
60 static const bool has_fixed_range =
false;
62 UniformSmallInt(base_type & rng, IntType min, IntType max);
63 result_type operator()()
66 return ((_rng() - _rng.min()) / _factor) % _range + _min;
68 result_type min()
const {
return _min; }
69 result_type max()
const {
return _max; }
71 typedef typename base_type::result_type base_result;
78template<
class UniformRandomNumberGenerator,
class IntType>
81 : _rng(rng), _min(min), _max(max),
82 _range(static_cast<base_result>(_max-_min)+1), _factor(1)
88 base_result r_base = _rng.max() - _rng.min();
89 if(r_base == std::numeric_limits<base_result>::max()) {
94 if(r_base % _range == 0) {
96 _factor = r_base / _range;
99 for( ; r_base/_range/32 >= _range; _factor *= 2)