How to create a Unique numeric ID
-
Hi, I need to create a unique id which consists only of numbers (0-9), and needs to be of a certain length (not more than 37 chars). How can I do this? I know that here is GUID, but this creates a hexidecimal number. Thanks
Well, I think it is far easier to change the
GUID
representation than writing your own algo to create a uniqueID
. Unfortunately, a 128-bit wide number (as GUID is) requires more than 38 decimal digits. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Well, I think it is far easier to change the
GUID
representation than writing your own algo to create a uniqueID
. Unfortunately, a 128-bit wide number (as GUID is) requires more than 38 decimal digits. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Well, I think it is far easier to change the
GUID
representation than writing your own algo to create a uniqueID
. Unfortunately, a 128-bit wide number (as GUID is) requires more than 38 decimal digits. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
yes - that's exactly my problem :) If I use part of the GUID that is generated and convert that to decimal. will that still be globaly unique?
SWDevil wrote:
If I use part of the GUID that is generated and convert that to decimal. will that still be globaly unique?
No. BTW why have you such a requirement constraint (just curious)? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
SWDevil wrote:
If I use part of the GUID that is generated and convert that to decimal. will that still be globaly unique?
No. BTW why have you such a requirement constraint (just curious)? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi, I need to create a unique id which consists only of numbers (0-9), and needs to be of a certain length (not more than 37 chars). How can I do this? I know that here is GUID, but this creates a hexidecimal number. Thanks
BTW, do you really need a Global Unique Identifier?
GUID
exist becauseID
creation must be shared (anyone may create his unique IDs via Guidgen) and not bound to a centralized mechanism (as the one assigning car license numbers), do you have such a strict requirement? :confused:If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Hi, I need to create a unique id which consists only of numbers (0-9), and needs to be of a certain length (not more than 37 chars). How can I do this? I know that here is GUID, but this creates a hexidecimal number. Thanks
Could you get away with using a timestamp (probably including milliseconds?) Thats nowhere _globally_ unique, but unique to every point in space. And maybe that is enough?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
Could you get away with using a timestamp (probably including milliseconds?) Thats nowhere _globally_ unique, but unique to every point in space. And maybe that is enough?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
I am thinking of using GetTickCount, but I understand that this might return a negative value? Is this true?
SWDevil wrote:
...GetTickCount...might return a negative value?
No. It returns a DWORD, that is unsigned. It wraps around after 49,7 days, though. Win95 used to crash after that uptime. Not that it was generally able to stay up that long without crash anyway.
time64
returns the seconds since UTC. It wraps around somtimes in the year 3000 If you really need, you could mix in the milliseconds since startup (GetTickCount)time64
relies on the computers clock being set - tampering with the clock *could* make your UID non-unique. That may or may not be a problem.Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency"