PRNGS don’t generally have a way to go backward in the sequence. Some are designed with an O(1)
method for skipping to a point in the sequence, but that’s a rarity as far as I know.
What you’ve found with GLOBAL_RNG.idxF
is an interesting implementation detail of the way that the MersenneTwister
is optimized for speed: it generates random numbers in batches and stores the batch in a cache. When you get to the batch size, idxF
will wrap around to 1, and your trick above will result in an index out of bounds error. It would be possible to design the cache for any PRNG to always allow going back in the sequence by up to a given number of slots but it’s a pretty unusual requirement.