I want to create a short GUID. Is there any way to create a short unique code like short GUID? I want to create a ticket tracking number.
The length of GUID is 128bits(16bytes), so if you want to create a short GUID , you have to change GUID's encoding.
How unique is unique? A GUID is a unique number that can be used as an identifier for anything in the universe, but unlike ISBN there is no central authority - the uniqueness of a GUID relies on the algorthm that was used to generate it.
Absolutely. Even if only one GUID is generated per second, we'll run out in a scant 9 quintillion years.
To Generate a GUID in Windows 10 with PowerShell, Type or copy-paste the following command: [guid]::NewGuid() . This will produce a new GUID in the output. Alternatively, you can run the command '{'+[guid]::NewGuid(). ToString()+'}' to get a new GUID in the traditional Registry format.
The length of GUID is 128bits(16bytes), so if you want to create a short GUID , you have to change GUID's encoding.
For instance, you can use base64 or ASCII85.
/// <summary> /// Creates a GUID which is guaranteed not to equal the empty GUID /// </summary> /// <returns>A 24 character long string</returns> public static string CreateGuid() { Guid guid = Guid.Empty; while (Guid.Empty == guid) { guid = Guid.NewGuid(); } // Uses base64 encoding the guid.(Or ASCII85 encoded) // But not recommend using Hex, as it is less efficient. return Convert.ToBase64String(guid.ToByteArray()); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With