How to create an injective function to generate pseudo-random numbers with seed

315 Views Asked by At

Let's call $A$ the set of all the $n$-digit natural numbers (base $10$).

So with $n=3$, they would be $000, 001, 002, \dots, 999$

Basic question:

I need to create a mathematic function with this features:

  • it maps numbers from $A$ to $A$ (it assigns to every number in A another number in $A$);
  • it's injective (it never maps distinct numbers to the same number);
  • the list of numbers generated by ordered numbers need to look like a random numbers list (see later for an explanation);
  • I need to control this randomness with a seed (a number that determines the function, same number, same couple of values).

When I talk about pseudo random generation I mean the numbers mapped need to look like a random series:

For example

  • $000 \to 956$
  • $001 \to 289$
  • $002 \to 392$
  • $003 \to 003$
  • $004 \to 128$

How can I generate a function like this?

Extended question:

How can I do the same using not $n$-digit natural numbers but sequences of $n$ digits taken from a custom alphabet (for example $[0,1,2,A,K,B]$).