![]() However, to address the need for a C based GUID function, here is code based on a JavaScript function. This example uses RegEx to create the GUID.īelow is code that will create a GUID based on the JavaSCript example. GUID (aka UUID) is an acronym for 'Globally Unique Identifier' (or 'Universally Unique Identifier'). I'm sure there are more elegant solutions out there. A Version 4 UUID is a universally unique identifier that is generated using random numbers. It is a 128-bit integer number used to identify resources. ![]() The term GUID is generally used by developers working with Microsoft technologies, while UUID is used everywhere else. You can either use or look at the code of Boost.Uuid : srand (clock()) Ĭhar *szTemp = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" Ĭase 'y' : break This is something cobbled together to help give a clean example for others to follow. Last time I checked (january 2010), I found at least the following implementations for Windows and Linux/Solaris (this info could be outdated): UUID/GUID on Linux/Solaris It is a C++ library, but still, you can find inside how the code author retrieved the Uuid on multiple systems. The Wikipedia page on GUID/UUID has a list of alternative implementations you could use/study: I went to google to search for a better approach of generating UUID and found out that there are many other open source libraries that are doing the same job and claiming that they are more efficient than others.ĬryptGenRandom to generate enough bytes to make up a GUID/UUID.CryptReleaseContext to release the acquired random context.CryptAcquireContext to acquire a random context.Open a file to /dev/urandom and read enough bytes (16) to make up a GUID/UUID. I found out this opensource library whose benchmarking results looks promising to me. There is a GUID/UUID type which is always random (the version 4), meaning that to be compatible with other GUID/UUID semantics, you should respect that. Now, you want the GUID/UUID to be ordered in time. The only way to do that without weakening the GUID/UUID randomness would be to prefix the 16-byte GUID/UUID with an unsigned integer (which would make your identifier data 20-bytes, or more, depending on your integer). Just generate a GUID/UUID, and increase the integer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |