全局唯一標識符(GUID,Globally Unique Identifier)是一種由算法生成的二進制長度為128位的數字標識符。GUID主要用於在擁有多個節點、多台計算機的網路或系統中。在理想情況下,任何計算機和計算機集群都不會生成兩個相同的GUID。GUID 的總數達到了2^128(3.4×10^38)個,所以隨機生成兩個相同GUID的可能性非常小,但並不為0。所以,用於生成GUID的算法通常都加入了非隨機的參數(如時間),以保證這種重複的情況不會發生。
GUID一詞有時也專指微軟對UUID標準的實現。
在 Windows 平台上,GUID 廣泛套用於微軟的產品中,用於標識如註冊表項、類及接口標識、資料庫、系統目錄等對象。
基本介紹
- 中文名:全局唯一標識符
- 外文名:GUID,Globally Unique Identifier
- 類型:數字唯一標識符
- 作用於:多節點、多計算機的網路或系統
格式
特點
爭議
程式
Option ExplicitPrivate Type GUIDData1 As LongData2 As IntegerData3 As IntegerData4(8) As ByteEnd TypePrivate Declare Function CoCreateGuid Lib "ole32.dll" (pguid As GUID) As LongPrivate Declare Function StringFromGUID2 Lib "ole32.dll" (rguid As Any, ByVal lpstrClsId As Long, ByVal cbMax As Long) As LongPrivate Function GUIDGen() As String '生成GUIDDim uGUID As GUIDDim sGUID As StringDim bGUID() As ByteDim lLen As LongDim RetVal As LonglLen = 40bGUID = String(lLen, 0)CoCreateGuid uGUID '把結構轉換為一個可顯示的字元串RetVal = StringFromGUID2(uGUID, VarPtr(bGUID(0)), lLen)sGUID = bGUIDIf (Asc(Mid$(sGUID, RetVal, 1)) = 0) Then RetVal = RetVal - 1GUIDGen = Left$(sGUID, RetVal)End Function
#include <objbase.h>#include <stdio.h>//--生成GUIDconst 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[]){//--COMCoInitialize(NULL);printf(newGUID());printf("\n");//--COMCoUninitialize();return 0;}
uses ActiveX;function ctGUID:string;varid:TGUID;beginCoCreateGuid(id);Result:=GUIDToString(id);end;
using System;namespace GUID測試 { class Program { static void Main(string[] args) { //產生一個新的GUID並輸出 Console.WriteLine(System.Guid.NewGuid()); Console.ReadKey(); } } }
import java.util.UUID;public class guid {/*** @param args*/public static void main(String[] args) {// TODO Auto-generated method stubUUID uuid = UUID.randomUUID();System.out.println(".{"+uuid.toString()+"}");}}
Function Guid_Gen:ansistring;Var s:string; i:longint;Begin s:='0123456789abcdef'; //8-4-4-4-12 Guid_Gen:='xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; for i:=1 to length(Guid_Gen) do begin if Guid_Gen[i]='x' then Guid_Gen[i]:=s[Random(16)+1]; end;End;
.版本 2.DLL命令 CoCreateGuid, , "ole32", "CoCreateGuid" .參數 guid, 位元組集.版本 2.子程式 生成新的GUID, 文本型.局部變數 guid, 位元組集.局部變數 a, 長整數型.局部變數 b, 整數型.局部變數 c, 整數型.局部變數 s, 文本型.局部變數 i, 整數型guid = 取空白位元組集 (16)CoCreateGuid (guid)a = 取位元組集數據 (取位元組集左邊 (guid, 4), #長整數型, )b = 取位元組集數據 (取位元組集中間 (guid, 5, 2), #整數型, )c = 取位元組集數據 (取位元組集中間 (guid, 7, 2), #整數型, )s = “”s = s + 取文本右邊 (“00000000” + 取十六進制文本 (a), 8) + “-”s = s + 取文本右邊 (“0000” + 取十六進制文本 (b), 4) + “-”s = s + 到小寫 (取文本右邊 (“0000” + 取十六進制文本 (c), 4)) + “-” ' 第三部分中的字母為小寫字母.計次循環首 (8, i) s = s + 取文本右邊 (“00” + 取十六進制文本 (guid [i + 8]), 2) .如果真 (i = 2) s = s + “-” .如果真結束.計次循環尾 ()返回 (“{” + s + “}”)
public function create_guid(){ $charid = strtoupper(md5(uniqid(mt_rand(), true))); $hyphen = chr(45);// "-" $uuid = substr($charid, 6, 2).substr($charid, 4, 2). substr($charid, 2, 2).substr($charid, 0, 2).$hyphen .substr($charid, 10, 2).substr($charid, 8, 2).$hyphen .substr($charid,14, 2).substr($charid,12, 2).$hyphen .substr($charid,16, 4).$hyphen .substr($charid,20,12); return $uuid; }
ExcelVBA
Function GetGuidToString() As String GetGuidToString = LCase(Mid$(CreateObject("Scriptlet.TypeLib").GUID, 2, 36))End Function
SAPABAP
Function modules GUID_CREATE, GUID_CONVERT, SYSTEM_UUID_C22_CREATE,
Function group SYST,
Function modules SYSTEM_UUID_CREATE, SYSTEM_UUID_C_CREATE, SYSTEM_GET_UNIQUE_ID