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