In my mobile application I have to provide the user with a random unique X alphanumeric code so that the user can reply with that alphanumeric code to perform some task.
The number of users going to use this application is around 1 million people and the message traffic is around 0.1 million messages/day.
I can use only 26 upper letters, 26 lower letters and 10 digits. If the random number size is 5 then I can generate 916132832 unique combinations. After the combinations get exhausted I want to recycle this number generation again.
I am looking for an algorithmic approach. Is there any algorithmic approach to solve this problem?
If you accept to recycle the random numbers, why do you want to wait for the exhaustion of the combinations before recycling?
I would just generate random numbers, without caring if they've been used already.
If you really really want to keep it like you asked, here's how you could do it:
You could improve it by moving the used numbers from one table to another, and use the second table instead of the first one when the first table is empty.
You could also do that in memory, if you have enough of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With