45 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
49 static const unsigned int max = 1UL<<31;
53 unsigned int next(
void);
60 unsigned int seed(
void)
const;
67 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
69 LinearCongruentialGenerator<m,a,q,r>::next(
void) {
70 s = a*(s%q) -
r*(s/q);
75 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
81 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
87 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
92 template<
unsigned int m,
unsigned int a,
unsigned int q,
unsigned int r>
95 unsigned int x1 = next() & ((1<<16)-1);
96 unsigned int x2 = next() & ((1<<16)-1);
98 double d =
static_cast<double>(((x1<<16) | x2) % max) / max;
99 unsigned int val =
static_cast<unsigned int>(n * d);
100 return (val < n) ? val : (n-1);
102 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.
unsigned int operator()(unsigned int n)
Returns a random integer from the interval [0..n)
LinearCongruentialGenerator(unsigned int s=1)
Construct the generator instance with seed s.
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
Post propagator for SetVar SetOpType SetVar SetRelType r