47 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
51 static constexpr unsigned int max_value = 1UL<<31;
55 unsigned int u(
unsigned int n);
57 unsigned long long int ull(
unsigned long long int n);
64 unsigned int seed(
void)
const;
90 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
91 forceinline
unsigned int
93 s = a*(s%q) - r*(s/q);
98 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
104 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
110 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
111 forceinline
unsigned int
116 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
117 forceinline
unsigned int
118 LinearCongruentialGenerator<m,a,q,r>::u(
unsigned int n) {
119 unsigned int x1 = next() & ((1U<<16)-1U);
120 unsigned int x2 = next() & ((1U<<16)-1U);
123 double d =
static_cast<double>(((x1<<16) | x2) % max_value) / max_value;
124 unsigned int val =
static_cast<unsigned int>(n * d);
125 return (val < n) ? val : (n-1);
127 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
128 forceinline
unsigned long long int
129 LinearCongruentialGenerator<m,a,q,r>::ull(
unsigned long long int n) {
131 return u(
static_cast<unsigned int>(n));
132 unsigned long long int x1 = next() & ((1LLU<<16)-1LLU);
133 unsigned long long int x2 = next() & ((1LLU<<16)-1LLU);
134 unsigned long long int x3 = next() & ((1LLU<<16)-1LLU);
135 unsigned long long int x4 = next() & ((1LLU<<16)-1LLU);
138 return ((x1 << 48) | (x2 << 32) | (x3 << 16) | x4) % n;
141 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
145 return static_cast<Type
>(ull(
static_cast<unsigned long long int>(n)));
147 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
148 forceinline
unsigned int
152 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
156 static_cast<int>(u(
static_cast<unsigned int>(n)));
158 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
159 forceinline
long long int
162 static_cast<long long int>
163 (ull(
static_cast<unsigned long long int>(n)));
165 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
Template for linear congruential generators.
size_t size(void) const
Report size occupied.
static constexpr result_type max()
Maximum value that may be produced when no bound is specified.
unsigned int result_type
Type of the produced values.
result_type operator()()
Returns a random integer from the interval .
static constexpr result_type min()
Minimum value that may be produced when no bound is specified.
LinearCongruentialGenerator(unsigned int s=1)
Construct the generator instance with seed s.
unsigned int next(void)
Generate next number in series.
void seed(unsigned int s)
Set the current seed to s.
unsigned int seed(void) const
Return current seed.
LinearCongruentialGenerator< 2147483647, 48271, 44488, 3399 > RandomGenerator
Default values for linear congruential generator.
Support algorithms and datastructures
Gecode toplevel namespace