1

Is there a function

permute(size, seed, i) -> j

that runs in constant time that computes a pseudorandom permutation? In other words,

[permute(size, seed, 0), permute(size, seed, 1), ..., permute(size, seed, size - 1)]

should be a pseudorandom shuffle of the numbers

[0, 1, ..., size - 1]

A linear congruential generator is close to workable (I don't need strong randomness guarantees for my application), but I want an algorithm that works for any size, and there needs to be a way to incorporate the seed.

1 Answers1

1

Use format-preserving encryption. If you search for "format-preserving" on this site and on Crypto.SE, you'll find many references. See, e.g., Incremental generation of random permutations?, Pseudo random, unqiue integer numbers in a given range, etc.

D.W.
  • 167,959
  • 22
  • 232
  • 500