Hey guys, this is very likely a total brain fart on my part but I was hoping someone could have a look at the following statement which describes how to set up the lagged fibonacci rng:
First, generate four million pseudo-random numbers using a specific form of what is known as a "Lagged Fibonacci Generator":
For 1 ≤ k ≤ 55, s(k) = [100003 − 200003k + 300007k^(3)] (modulo 1000000) − 500000.
For 56 ≤ k ≤ 4000000, s(k) = [s(k−24) + s(k−55) + 1000000] (modulo 1000000) − 500000.
Thus, s(10) = −393027 and s(100) = 86613.
So seems pretty straightforward (this is used to generate the matrix, which is then the actual problem to be solved, this link has the question). Anyways, here is my implementation and its output for s(10) and s(100):
class lagged_fib
{
private:
typedef std::deque<int> seed_list;
seed_list seeds;
size_t k;
public:
lagged_fib()
{
k = 1;
}
int operator()()
{
if (k<56)
{
seeds.push_back(((100003 - 200003*k + 300007*k*k*k)%1000000) - 500000);
k++;
}
else
{
seeds.push_back(((seeds[31]+seeds[0]+1000000)%1000000) - 500000);
seeds.pop_front();
}
return seeds.back();
}
};
Which yields:
s(10) = -393027
s(100) = -422827
You'll note that s(10) is as expected (so assumably the first part of the algorithm is correct), but s(100) is not. So, hopefully someone can spot where I've gone wrong, this is driving me up the wall.
Thanks