41template <
typename IntType, IntType a, IntType c, IntType m, IntType val>
42class LinearCongruential
46 typedef IntType result_type;
47 static const bool has_fixed_range =
true;
48 static const result_type min_value = (c == 0 ? 1 : 0);
49 static const result_type max_value = m - 1;
50 static const IntType multiplier = a;
51 static const IntType increment = c;
52 static const IntType modulus = m;
54 result_type min()
const {
return c == 0 ? 1 : 0; }
55 result_type max()
const {
return m - 1; }
56 explicit LinearCongruential(IntType x0 = 1)
71 IntType getState()
const {
return _x; }
77 static IntType apply(IntType x)
79 return x = utils::const_mod<IntType, m>::mult_add(a, x, c);
81 bool validation(IntType x)
const {
return val == x; }
82 bool operator==(
const LinearCongruential& rhs)
const
87 inline void checkSeed(IntType x)
89 if (_x < min() || _x >= max())
90 throw FatalErrorException(A_FUNCINFO, String::format(
"Invalid seed v={0} min={1} max={2}", x, min(), max()));