mercredi 5 août 2015

Where did I find prng using seed = seed*a % 0x10001?

Where did I find prng using seed = seed*a % 0x10001?

Seed non-zero and “a” such that a complete sequence 1..0x10000 is produced. Examples for a: 3, 0x0BAD, 0xC0DE and over 32000 others.

The charm of such a generator is that the seed*a product can be reduced mod 0x10001 with little more than a subtraction. I have used it storing seed-1, which takes on all values 0..0xFFFF.

I know that the range of this generator is short and that it has a period of 65536 after which it repeats. But using different suitable values of “a” and 16-bit xor it’s useful to visit all items in a list of no more than 65536 items exactly once in a random sequence.

I can’t imagine a serious cryptographic use for such a sequence but generating creating 16-bit s-box values comes to mind.

I thought I read it in TAOCP in the chapter on random numbers. But my memory or my eyesight has failed me.

But where did I find this sequence and the algorithm for validating suitable “a” values? I would like to give credit in my code.




Aucun commentaire:

Enregistrer un commentaire