I have one hundred integers in $\{0,1,2,3,4,5\}$ which I suspect are consecutive values of $⌊𝑥_𝑛/2^{16}⌋\bmod6$$\lfloor x_n/2^{16}\rfloor\bmod6$ computed as $𝑥_{𝑛+1}:=𝑎⋅𝑥_𝑛+𝑏\bmod𝑚$$x_{n+1}:=a\cdot x_n+b\bmod m$, with $𝑚=2^{31}$$m=2^{31}$, and $(𝑎,𝑏)∈{(214013,2531011),(22695477,1)}$$(a,b)\in{(214013,2531011),(22695477,1)}$. How do I validate that hypothesis, find the $(𝑎,𝑏)$$(a,b)$ used, and predict what follows in the sequence?
What is the better way to do it? I just started to learn c++ two weeks ago, please forgive my ignorance.
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <iostream>
#include <inttypes.h>
using namespace std;
const int RESULT[3][7] = {
{0,1,0,1,1,1,1},
{1,0,1,0,0,0,0},
{0,1,1,0,1,0,0}
};
static unsigned long x;
int test_rand(void)
{
x = 214013 * x + 2531011; // or is it 22695477*x+1
return (int)((x >> 16) & 0x7FFF);
};
int onlyx16(void)
{
x = 214013 * x + 2531011; // or is it 22695477*x+1
return (x >> 16) & 1;
};
void chk_seed(unsigned long seed)
{
int d1[241]{};
int d2[241]{};
int d3[241]{};
x = seed;
for (int i = 0; i < 2399; i++) {
test_rand();
}
for (int i = 0; i < 241; i++)
{
d1[i] = onlyx16();
d2[i] = onlyx16();
d3[i] = onlyx16();
};
int correct = 0;
for (int k = 0; k < 236; k++)
{
correct = 0;
for (int i = 0; i < 7; i++)
{
if ((d1[i + k]) == RESULT[0][i])
{
correct += 1;
}
else {
correct = 0;
break;
};
if ((d2[i + k]) == RESULT[1][i])
{
correct += 1;
}
else {
correct = 0;
break;
};
if ((d3[i + k]) == RESULT[2][i])
{
correct += 1;
}
else {
correct = 0;
break;
};
};
if (correct == 21)
{
printf("seed 0x%d is OK\n", seed);
printf("results forecast:\n");
for (int round = 0; round < 5; round++)
{
printf("round%d ", round + 1);
int new_d[3]{};
for (int i = 0; i < 3; i++)
{
new_d[i] = test_rand()% 6;
printf("%d", new_d[i]);
};
printf("\n");
}
};
}
};
int main()
{
for (unsigned long seed = 0; seed < 0x100000000; seed++)
chk_seed(seed);
};