algorithmrandomintegerbijection

Pseudo-random-looking one-to-one int32->int32 function


I am looking for a int32->int32 function that is


Solution

  • Multiply by a large odd number and xor with a different one.

    Bijection: odd numbers have a multiplicative inverse modulo powers of two, so the multiplication is undone by a multiplication by the inverse. And xor is, of course, undone by another xor.

    This is basically how the linear congruence pseudo random number generator works.