Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to create a Unique numeric ID

How to create a Unique numeric ID

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SWDevil
    wrote on last edited by
    #1

    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

    C J 3 Replies Last reply
    0
    • S SWDevil

      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

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Well, I think it is far easier to change the GUID representation than writing your own algo to create a unique ID. 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.

      S 2 Replies Last reply
      0
      • C CPallini

        Well, I think it is far easier to change the GUID representation than writing your own algo to create a unique ID. 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.

        S Offline
        S Offline
        SWDevil
        wrote on last edited by
        #3

        yes - that's exactly my problem :)

        1 Reply Last reply
        0
        • C CPallini

          Well, I think it is far easier to change the GUID representation than writing your own algo to create a unique ID. 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.

          S Offline
          S Offline
          SWDevil
          wrote on last edited by
          #4

          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?

          C 1 Reply Last reply
          0
          • S SWDevil

            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?

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #5

            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.

            S 1 Reply Last reply
            0
            • C CPallini

              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.

              S Offline
              S Offline
              SWDevil
              wrote on last edited by
              #6

              The requirement is a 64 char string. But there is a first part that I have to include, and for the second part I have to generate a unique ID. Both parts together should not be mopre than 64 chars.

              1 Reply Last reply
              0
              • S SWDevil

                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

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                BTW, do you really need a Global Unique Identifier? GUID exist because ID 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.

                1 Reply Last reply
                0
                • S SWDevil

                  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

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #8

                  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"

                  S 1 Reply Last reply
                  0
                  • J jhwurmbach

                    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"

                    S Offline
                    S Offline
                    SWDevil
                    wrote on last edited by
                    #9

                    I am thinking of using GetTickCount, but I understand that this might return a negative value? Is this true?

                    J 1 Reply Last reply
                    0
                    • S SWDevil

                      I am thinking of using GetTickCount, but I understand that this might return a negative value? Is this true?

                      J Offline
                      J Offline
                      jhwurmbach
                      wrote on last edited by
                      #10

                      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"

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups