EDIT: There is a much more clever algorithm based on block ciphers that I think Geoff will write up.
There are two common algorithms for generating permutations. Knuth's shuffle is inherently sequential so not a nice choice for parallelism. The other is random selection with retry any time repetition is encountered. Random selection is clearly equivalent when applied in any order, thus I propose the following simple algorithm:
- Randomly sample candidate
p[i]
in [0,n-1]
for each i
in Needed
(in parallel).
- Remove all non-collided entries from
Needed
, as well as (optionally) some deterministic choice from the collisions (e.g., keep p[i]
if i < {j | p[j] = p[i]}
).
- Repeat from step 1 with new (smaller) set
Needed
.
Since we haven't lost entropy in this process, the result is essentially equivalent to sequential random sampling in some different order, starting with the locations i
that did not collide (we just didn't know that order in advance). Note that if we used the computed value in a comparison, for example, we would have introduced bias.