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

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, ... 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 -> 956
001 -> 289
002 -> 392
003 -> 003
004 -> 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]).

• What you seeks seems to be a random permutation, see en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle for an algorithm – gammatester Sep 5 '18 at 18:09
• Yes! That's it... I can use a pseudo-random number generator (with seed) to shuffle the set, so I can obtain the same shuffle order with the same seed. Thanks! – mugnozzo Sep 6 '18 at 8:05