mercredi 31 mai 2023

Re-roll next value in pseudo-random sequence without changing any other values

I would like a pseudo-random number generator which generates an effectively-infinite (i.e. very large period) sequence that can be traversed in both directions but also allows re-rolling the value under the cursor.

For example, a starting view of the state (with square brackets indicating the cursor position) might be:

... 1 7 3 [8] 4 1 6 ...

After stepping the generator forward twice, the sequence 8 4 is generated and the view is:

... 3 8 4 [1] 6 0 8 ...

Then, the application chooses to re-roll the cursor value from 1, and the generator produces 7, resulting in the view:

... 3 8 4 [7] 6 0 8 ...

From this point, even if the cursor is moved backward, the newly generated value of 7 will remain in place of the original 1. However, all other elements of the sequence will be unchanged:

... 7 3 8 [4] 7 6 0 ...

I considered using a reversible linear-feedback shift register (to allow stepping both left and right in the sequence) and writing to some set of bits in the center of the register to re-roll. However, to prevent re-rolling from affecting the rest of the sequence, only bits beyond the final tap can be re-rolled, and upon considering for a while, I realized it is probably not possible for a LFSR whose final tap is not all the way at the edge of the bit stream to be reversed.




Aucun commentaire:

Enregistrer un commentaire