Let A be a sequence [1, N) of integers, for example, for N=5: 0,1,2,3,4. Then lets randomly shuffle it into S (for N=5, it could be: 4,1,3,2,0). Is there any smart way to compress S (randomized array that contains each integer from [0, N) exactly once)?
The best thing I could come up with doesn't sounds like an optimal solution: maintain a list of "unused" integers (initialized with [0, N)) and output each sequence item as an index from that list using minimum amount of bits (since unused will become smaller, number of bits required to output each index will decrease as well). Something like this:
unused = [0, N)
for x in S:
k = index of x in unused
nbits = log2(len(unused))
output k as nbits integer
remove x from unused