Sorry if my question is stupid, math has been always a wild beast for me. I am an application developer. In one application I have a module which assigns a random 6-8 digit number and a serial number to a manager. The manager can then give these two numbers to other people who uses them as credit on the application. Currently There are 134 managers and each manager can generate 50 codes per day.
To implement it I have a table that contains these records.
- Serial No (starts from 1 and keeps on incrementing)
- Authorization code (random number 6-8 digit. Non repetitive)
- Manager code (code of manager who has generated it.)
- Is Used? (1 if code has been used else 0)
- Used on (date on which it was used so that we can delete this code so that authorization code can be reused.)
Whenever a manager tries to generate a code, the program creates a random number and see if this number is present or not in the table. If it is present, I regenerate or else I store it in the table.
So far so good, but the problem comes when many numbers are in use.
Currently there are 1090083 code in table. The total possible will be $99999999-999999 = 99000000$.
But at this very tiny amount only, I am having 2-8 collisions, i.e, the random number is already there and I have to generate another. This creats a lag and as the table grows it will soon become deamon.
According to me the problem lies with generation of numbers. Therefore I request you people to help me.
Is it possible to create a function on whose each ireatation a new non-repetitive number is outputed? So that I simply run it $n$ times to get $n$ numbers. Or any things else since you know the problem well.