GUID/UUID
Globally uniqueIdentifierGUID (Globally Unique Identifier) is an algorithmically generatedBinaryA 128-bit numeric identifier. GUIDs are mainly used in networks or systems with multiple nodes or computers. Ideally, any computer andComputer clusterNo two identical GUIDs will be generated. The total number of GUIDs is 2^128 (3.4×10^38), so the probability of randomly generating two identical GUIDs is very small, but not zero. Therefore, the algorithms used to generate GUIDs usually add non-random parameters (such as time) to ensure that such duplication does not occur.
The format of the GUID is "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", where each x is a number in the range 0-9 or af.hexadecimalFor example: 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid GUID value.
1. When a GUID is needed, it can be automatically generated by an algorithm without the need for an authoritative organization to manage it.
The potential drawbacks of GUID values have been raisedConfidentialityAdvocateIn March 1999, the Federal Trade Commission of the United States was asked toMicrosoftThe controversy mainly concernsOffice 97andOffice 2000Documents use GUID values. Office documents, such as Word files orExcelelectronicData Sheet, the GUID values used are invisible to the user. However, there are many reports that the author of a document can be tracked by tracing the GUID value, and even if the author has adopted special methods, they can still be tracked. In response to the above problems, Microsoft has released a patch version of Office 97 SR2, which disables the use of the GUID function and can also remove the GUID of existing documents.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | Option Explicit Private Type GUID Data1As Long Data2 As Integer Data3As Integer Data4(8) As Byte End Type Private Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As Long Private Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any, ByVal lpstrClsId As Long, ByVal cbMax As Long) As Long Private Function GUIDGen() As String 'Generate GUID Dim uGUID As GUID Dim sGUID As String Dim bGUID() As Byte Dim lLenAs Long Dim RetVal As Long lLen = 40 bGUID = String(lLen, 0) CoCreateGuid uGUID 'Convert the structure into a displayable string RetVal = StringFromGUID2(uGUID, VarPtr(bGUID(0)), lLen) sGUID = bGUID If (Asc(Mid$(sGUID, RetVal, 1)) = 0) Then RetVal = RetVal - 1 GUIDGen = Left$(sGUID, RetVal) End Function |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include #include //--Generate GUID const char* newGUID() { static char buf[64] = {0}; GUID guid; if (S_OK == ::CoCreateGuid(&guid)) { _snprintf(buf, sizeof(buf) , "{%08X-%04X-%04x-%02X%02X-%02X%02X%02X%02X%02X%02X}" , guid.Data1 , guid.Data2 , guid.Data3 , guid.Data4[0], guid.Data4[1] , guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5] , guid.Data4[6], guid.Data4[7] ); } return (const char*)buf; } int main(int argc, char* argv[]) |