A Universally Unique IDentifier (UUID) - also called a Global Unique IDentifier (GUID) -
is a 128-bit value formatted into blocks of hexadecimal digits separated
by a hyphen ("-", U+002D). A typical UUID is AA97B177-9383-4934-8543-0F91A7A02836
.
It doesn't matter whether the letters A-F are upper or lower case.
A version 4 UUID is defined in RFC 4122: 128 randomly-generated bits with six bits at certain positions set to particular values. For example,
AA97B177-9383-4934-8543-0F91A7A02836 ^ ^ 1 2
The digit at position 1 above is always "4" and the digit at position 2 is always one of "8", "9", "A" or "B".
The procedure to generate a version 4 UUID is as follows:
The following code using the CryptoSys PKI Toolkit shows how to create a version 4 UUID according to RFC 4122.
Programming language | Source code |
---|---|
VB6/VBA | UUID.bas |
VB.NET/VB2005+ | Uuid.vb |
C# | Uuid.cs |
C/C++ | Uuid.c |
Typical output looks like
6948DF80-14BD-4E04-8842-7668D9C001F5 4B8302DA-21AD-401F-AF45-1DFD956B80B5 8628FE7C-A4E9-4056-91BD-FD6AA7817E39 10929DF8-15C5-472B-9398-7158AB89A0A6 ED280816-E404-444A-A2D9-FFD2D171F928 D952EB9F-7AD2-4B1B-B3CE-386735205990 3F897E85-62CE-4B2C-A957-FCF0CCE649FD 8E7C2F0A-6BB8-485C-917E-6B605A0DDF29 1AD2F3EF-87C8-46B4-BD1D-94C174C278EE AA97B177-9383-4934-8543-0F91A7A02836
Set the two most significant bits (bits 6 and 7) of the clock_seq_hi_and_reserved to zero and one, respectively.The author is using the bit-ordering convention where the least-significant bit is numbered 0 and the most-significant bit is "bit 7".
7 6 5 4 3 2 1 0 +-+-+-+-+-+-+-+-+ |1|0| | | | | | | +-+-+-+-+-+-+-+-+
2020-03-12:
Added new function
RNG_Guid
(.NET Rng.Guid Method
)
to generate a random 36-character Global Unique IDentifier (GUID) string.
For more information or to comment on this page, please send us a message.
This page last updated 10 September 2025