Imagine that I managed to shuffle all numbers between 0 and 2 ^ 32, using something like a Knuth shuffle and a sowing random number generator, seeded with a key.
Conceptually, I need two arrays (using Z 5 instead of Z 2 32 for short):
[2, 0, 1, 4, 3]
If I had these arrays, I could efficiently look for the nth element in the permutation, and also discover the purmutation v value with the element;
v = perm[n]; n == inv[v]; // true
I don't want to store two 16 gigabyte uint arrays representing this shuffled set, because I am never interested in the whole shuffled sequence at any time. I'm only interested in the value of the nth element.
Ideally, I want to write two pure functions that work as follows:
uint nthShuffled = permutate<uint>(key, n);
Requirements:
- Each 32-bit value displays a unique 32-bit value.
- Knowldedge of the first 100 elements in the permutation does not contain information about what may be the 101st element in the permutation.
I understand that theoretically there should be at least 2 32 ! unique keys to represent any possible permutation, but I believe that I can hide this problem in practice behind a good hash function.
Is there anything close to this?
source share