Depends on how many of those you need, how fast you are creating them, if they have to be unique only on your machine or for multiple machines, what characters (digits only, alphanumeric, ...), you want to allow, ... Generating unique IDs is not an easy task.
A few ideas:
The easiest (but of course not random at all) way is starting at 0000000000
and going up all the way up to zzzzzzzzzz
by just incrementing.
The safest way (but probably the slowest) is storing the generated IDs, and when you generate a new one, check if it already exists ...
Base your ID on the current timestamp + some internal incrementor (for ids generated at the same timestamp, depending on the resolution of your timestamp) + optionally machine configuation if you need it to be unique among multiple machines + some random + some shuffling.
But the more randomness you put into your ID, the less control you have on the output, thus you need to check for collisions. Especially if the number of generated IDs is large, with respect to the number of possible IDs.
So in the end of the day, there are only two ways to guarantee uniqueness (within a certain scope)
- check if the newly created id was already issued before
- calculated by a collision-free function, and you are in control that the input to this function cannot be used twice (for instance by incrementing the input after each id you generate)