Is it possible to develop a custom algorithm for generating unique GUIDs?

GUIDs are generated by a combination of numbers and hyphenated characters.

eg) {7B156C47-05BC-4eb9-900E-89966AD1430D}

In Visual Studio we have a Generate GUID tool to create it. I hope the same can be created programmatically through the windows API.

How are GUIDs unique? Why don't they use special characters like #, ^, etc.

Also is it possible to develop a custom algorithm for generating unique GUIDs?

+2


a source to share


5 answers


Yes, you can, but you shouldn't try to reinvent the wheel without a good reason to do so. GUIDs are unique, including items that are (statistically speaking) unlikely to be the same in two different cases, for example:

  • Current timestamp
  • System update
  • System MAC address
  • Random number
  • ...


Also, consider the privacy implications of GUIDs if you are implementing one from scratch, because they contain the above data that some people think is sensitive.

+3


a source


UUIDs are defined eg. at http://www.faqs.org/rfcs/rfc4122.html . One problem with using your own algorithm to generate something like a UUID is that you might collide with other people's UUIDs. So you should definitely use some other implementation if at all possible, and if not, write your own implementation of one of the standard algorithms.



+3


a source


Just to answer this question: why don't they use any special characters like #, ^, etc.

It is assumed to be a 128-bit integer. So the overall representation is a simple 32 hexadecimal.

You can create 128 characters 1 and 0, etc.

As for the rest of the question, the wiki has good answers.

+1


a source


You must create a new GUID by calling the API designed for it. In the native windows of the earth it is CoCreateGUID

; in .NET land is System.Guid.NewGuid()

;

+1


a source


Yes, although it's easier to use someone else, for example. Boost uuid

0


a source







All Articles