4 * Copyright (c) 2007 Des Higgins, Julie Thompson and Toby Gibson.
9 #include "RandomGenerator.h"
15 * The contructor initialises the random algorithm.
19 RandomGenerator::RandomGenerator(unsigned long s)
20 : m(100000000), m1(10000)
27 a[j] = (mult(31, a[j - 1]) + 1) % m;
33 * additive congruential method.
35 * @return unsigned long random number in the range 0 to r-1
37 unsigned long RandomGenerator::addRand(unsigned long r)
43 a[j] = (a[x] + a[y]) % m;
45 return (((a[j] / m1) *r) / m1);
54 unsigned long RandomGenerator::mult(unsigned long p, unsigned long q)
56 unsigned long p1, p0, q1, q0;
62 return ((((p0 *q1 + p1 * q0) % m1) *m1 + p0 * q0) % m);