I need to generate a random string 8 digit long and next time when I generate the random number make sure it was not already generated. If we simply think I have to store every confirmation number generated and every time I try to generate a new one, verify that it was not already generated by looking at the stored values.
In my case the numbers are stored in database.
But if the already generated numbers are a lot, it can take significant time to validate that. What is the best way to approach this problem? This should work something like youtube video Id. It probably never happens that by chance youtube video id generator generates same video id twice. So they are definitely verifying that each time they generate a new videoid that it wasn't already generated and used for some other video. There can be a lot of them.
By feasible amount of time I mean something that would be useful to use from the website. If for a user of a website, I am asking certain information and creating a unique identifier for him/her, then I don't want the website to be slow because I am verifying that the randomly generated identifier doesn't already exist in the database.