I have a pseudo-random number generator, that I am trying to understand. I have no relevant knowledge about math. I'm hoping that you can identify if this is a well-known algorithm and what its name is, so I can read a little about it.
This is the algorithm:
int random_seed = 1;
void random() {
random_seed = 16807 * random_seed + (random_seed / 127773) * -2147483647;
if (random_seed == 0) {
random_seed = std::numeric_limits<int>::max();
}
}
int main()
{
for (int x = 0; x < 10; x++) {
random();
std::cout << random_seed << std::endl; // This prints the results on the screen
}
}
Which prints the following pseudo-random generated numbers on the screen:
16807
282475249
1622650073
984943658
1144108930
470211272
101027544
1457850878
1458777923
2007237709
I found out that 16807 is related to the Lehmer random number generator, which is defined as:
${\displaystyle X_{k+1}=a\cdot X_{k}{\bmod {m}},}$
where $a$ is the multiplier 16807
and $X_{k}$ would be the random_seed.
$m$ is the modulus which in Lehmer's is $2^{31}-1$ and would be $2{,}147{,}483{,}647$. However, in the code example it is $-2{,}147{,}483{,}647$.
However, $m$ is not used as a modulus but as a factor. And it is not $2{,}147{,}483{,}647$ but $-2{,}147{,}483{,}647$. Then there's the question about the addition of the quotient of $X_{k} / 127773$. I haven't really found something helpful to me when searching for number $127773$.
Do you recognize any well-known pseudo-random number generator in the provided code? What could it be?