The Algorithm
We can use Brent’s Algorithm to detect infinitelyrepeating sequences in a list of values generated by some iterated function: that is, any list in which the next value in the sequence is generated from the previous value alone; if we find duplicate values in the list, we know we have a cycle.
The implementation below isn’t particularly elegant, and since I want to use it as a standalone tool I’m having it output strings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 

Randomness is hard…
Linear Congruential Generator’s are
notoriously easy to screw up
with the wrong parameters. Let’s use our function to test just how
finicky this RNG algorithm can be. random stream g4
is almost identical to
g5
, a knowngood generator. Let’s compare the two with a cut off limit of
999,999. First the good:
1 2 

Great, now let’s see how our typoed generator fares:
1 2 

… yikes.