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#
  4. How do I generate a Unique AlphaNumeric ID in C#

How do I generate a Unique AlphaNumeric ID in C#

Scheduled Pinned Locked Moved C#
csharphelpquestion
5 Posts 5 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.
  • E Offline
    E Offline
    ebukaegonu2
    wrote on last edited by
    #1

    i have tried Guid.NewGuid().ToString().GetHashCode().ToString("x").ToUpper(); but I do not get Unique Codes after 10,000 tries i need to add ABCDEFGHIJKLMNOPQRSTUVWXYZ and 1234567890 somebody help!!!

    N B I M 4 Replies Last reply
    0
    • E ebukaegonu2

      i have tried Guid.NewGuid().ToString().GetHashCode().ToString("x").ToUpper(); but I do not get Unique Codes after 10,000 tries i need to add ABCDEFGHIJKLMNOPQRSTUVWXYZ and 1234567890 somebody help!!!

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      How many characters do you need? There are a number of random password generators available, have you looked? One of those should be sufficient.


      No comment

      1 Reply Last reply
      0
      • E ebukaegonu2

        i have tried Guid.NewGuid().ToString().GetHashCode().ToString("x").ToUpper(); but I do not get Unique Codes after 10,000 tries i need to add ABCDEFGHIJKLMNOPQRSTUVWXYZ and 1234567890 somebody help!!!

        B Offline
        B Offline
        BobJanova
        wrote on last edited by
        #3

        GUIDs are unique (before you mess about with hashcodes and stuff). What is your requirement and why can't you use those?

        1 Reply Last reply
        0
        • E ebukaegonu2

          i have tried Guid.NewGuid().ToString().GetHashCode().ToString("x").ToUpper(); but I do not get Unique Codes after 10,000 tries i need to add ABCDEFGHIJKLMNOPQRSTUVWXYZ and 1234567890 somebody help!!!

          I Offline
          I Offline
          Ian Shlasko
          wrote on last edited by
          #4

          GUIDs are large enough that they'll usually be unique (But not guaranteed)... But once you take the hash code, you're dropping from a 16-byte GUID to a 4-byte integer, and limiting it even more by the hashing algorithm... So why not build your own algorithm? If you just need them to be unique, you can start from "AAAA" (Or whatever length) and just increase as if it was a number... AAAA, AAAB, AAAC, ..., AAAZ, AAA0, AAA1, and so on. If you want them to look random and be unpredictable, just generate a number of random integers from 0 to 36, and convert each one to a letter or digit... String them together, and you've got a random ID... Then just keep a hash/dictionary of previous IDs to compare against, and re-generate if you create a duplicate.

          Proud to have finally moved to the A-Ark. Which one are you in?
          Author of the Guardians Saga (Sci-Fi/Fantasy novels)

          1 Reply Last reply
          0
          • E ebukaegonu2

            i have tried Guid.NewGuid().ToString().GetHashCode().ToString("x").ToUpper(); but I do not get Unique Codes after 10,000 tries i need to add ABCDEFGHIJKLMNOPQRSTUVWXYZ and 1234567890 somebody help!!!

            M Offline
            M Offline
            Matt Meyer
            wrote on last edited by
            #5

            Guid should already satisfy your requirement in creating unique identifiers. They're already a product of cryptographic hashing functions, so you shouldn't need to hash them again. You can use ToString with a format provider to get a string representation of the value without the dashes. Or, as an alternative, you can always roll your own UUID implementation according to the standards. One other note - GetHashCode isn't a cryptographic hash, nor is it guaranteed to be consistent between frameworks or platforms. Check the Remarks section at MSDN.

            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