Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've a problem that I would not able to create the unique id having 9 digits. Please any possible clue that might help this problem..
Posted

Great answer from Walt.

But do you really need a 9 digit number? You could also use a UUID as Identifier:

Generating unique IDs[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Mar-12 2:30am    
Strictly speaking, the probability of uniqueness of UUID is very high, but not exactly 100%. Probably uniqueness of MAC address makes it unique. Anyway, it all depends on the scope of uniqueness. In the scope where a singleton or a system-wide singleton is feasible, an unsigned integer of sufficient size is the best, and UUID is just redundant.
--SA
TorstenH. 26-Mar-12 9:18am    
well, a UUID is a 32 digit value / a 128 bit value.

That should leave enough room to make it a unique ID at mostly all times. If you really find a non unique ID you probably should go for some lottery too.

But check the link, there are some more easy ideas on how to get an unique ID.
Sergey Alexandrovich Kryukov 27-Mar-12 23:25pm    
I understand that. Yes, the link is good. I voted 5.
--SA
I have no idea what your application or constraints are, but if you simply keep a counter and increment it each time you get a number, that will give you a unique id each time. If you use decimal digits, there would be 10^9 of those available before repeating. If you use hexadecimal, there would be 16^9, etc.

If you need something more random, then you will probably have to generate a random number and check to see that it hasn't been used before, which likely means storing up to 10^9 of those.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 26-Mar-12 2:27am    
Random is not good enough, because you would need to store them all in order to enforce uniqueness. The right answer depends on the scope of uniqueness. Ideally, if your method is applicable, it's the best one. Also, consideration about number of digits is gibberish: the ID should be defined by integer type, number of bits. The width of text presentation of it does not matter. Overall, I voted 4.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900