![]() |
VOOZH | about |
dotnet add package NUlid --version 1.7.3
NuGet\Install-Package NUlid -Version 1.7.3
<PackageReference Include="NUlid" Version="1.7.3" />
<PackageVersion Include="NUlid" Version="1.7.3" />Directory.Packages.props
<PackageReference Include="NUlid" />Project file
paket add NUlid --version 1.7.3
#r "nuget: NUlid, 1.7.3"
#:package NUlid@1.7.3
#addin nuget:?package=NUlid&version=1.7.3Install as a Cake Addin
#tool nuget:?package=NUlid&version=1.7.3Install as a Cake Tool
👁 Build Status
👁 Nuget version
A .Net ULID implementation
A GUID/UUID can be suboptimal for many use-cases because:
A ULID however:
PM> Install-Package NUlid
Or simply use the Nuget package manager GUI in Visual Studio.
Creating a ULID:
// Create a ULID
var myulid = Ulid.NewUlid();
// Print ULID
Console.WriteLine(myulid);
Output:
01ASB2XFCZJY7WHZ2FNRTMQJCT
Parsing a ULID:
// Parse ULID:
var myulid = Ulid.Parse("01ASB2XFCZJY7WHZ2FNRTMQJCT");
// Print time-part of ULID:
Console.WriteLine(myulid.Time);
Output:
4-8-2016 15:31:59 +00:00
You can also convert from/to GUID/UUID's, get the byte-representation of a ULID, create a ULID with specific timestamp and you can even specify an to use for generating the randomness (by default NUlid uses the but a is also provided, as well as a ). The ULID is implemented as a struct with (operator) overloads for (in)equality, comparison etc. built-in and is, generally, very much like .Net's native Guid struct. An extensive helpfile is provided in the Nuget package and also serves as a (simple) demonstration of NUlid's features.
Below is the current specification of ULID as implemented in this repository.
01AN4Z07BY 79KA1307SR9X4MV3
|----------| |----------------|
Timestamp Randomness
10 chars 16 chars
48bits 80bits
base32 base32
Timestamp
Randomness
As of v1.4.0 monotonic ULID's are supported (see below).
When generating a ULID within the same millisecond, it is possible to provide some guarantees regarding sort order (with some caveats). When you use the MonotonicUlidRng and a newly generated ULID in the same millisecond is detected, the random component is incremented by 1 bit in the least significant bit position (with carrying). For example:
// Create monotonic rng
var rng = new MonotonicRng();
// Create ULIDs, assume that these calls occur within the same millisecond:
Console.WriteLine(Ulid.NewUlid(rng)); // 01DBN5W2SG000DCBVYHX4T6MCX
Console.WriteLine(Ulid.NewUlid(rng)); // 01DBN5W2SG000DCBVYHX4T6MCY
Console.WriteLine(Ulid.NewUlid(rng)); // 01DBN5W2SG000DCBVYHX4T6MCZ
Console.WriteLine(Ulid.NewUlid(rng)); // 01DBN5W2SG000DCBVYHX4T6MD0
Console.WriteLine(Ulid.NewUlid(rng)); // 01DBN5W2SG000DCBVYHX4T6MD1
Console.WriteLine(Ulid.NewUlid(rng)); // 01DBN5W2SG000DCBVYHX4T6MD2
By default the most significant bit of the random part is set to zero; this ensures you can generate enough ULID's after the initial one before causing an overflow. Some implementations simply pick a random value for the random part and increment this value, however, there's a (very small) chance that this random part is close to the overflow value. If you then happen to generate a lot of ULID's within the same millisecond there is a risk the you hit the overflow. By our method we ensure there's enough 'room' for new values before 'running out of values' (overflowing). It is, with some effort, even possible to 'resume counting' from any given ULID.
Crockford's Base32 is used as shown. This alphabet excludes the letters I, L, O, and U to avoid confusion and abuse.
0123456789ABCDEFGHJKMNPQRSTVWXYZ
The components are encoded as 16 octets. Each component is encoded with the Most Significant Byte first (network byte order).
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 32_bit_uint_time_high |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 16_bit_uint_time_low | 16_bit_uint_random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 32_bit_uint_random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 32_bit_uint_random |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ttttttttttrrrrrrrrrrrrrrrr
Where:
t is Timestamp
r is Randomness
Based on / inspired by alizain/ulid.
Below measurements are based on an Intel(R) Core(TM) i9-10900X CPU @ 3.70Ghz:
BenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.4061)
Intel Core i9-10900X CPU 3.70GHz, 1 CPU, 20 logical and 10 physical cores
.NET SDK 9.0.204
[Host] : .NET 9.0.5 (9.0.525.21509), X64 RyuJIT AVX-512F+CD+BW+DQ+VL
DefaultJob : .NET 9.0.5 (9.0.525.21509), X64 RyuJIT AVX-512F+CD+BW+DQ+VL
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|------------------------------------- |-----------:|----------:|----------:|-------:|----------:|
| Guid.NewGuid() | 61.045 ns | 0.4488 ns | 0.3978 ns | - | - |
| Ulid.NewUlid(SimpleUlidRng) | 35.331 ns | 0.2170 ns | 0.1694 ns | - | - |
| Ulid.NewUlid(CSUlidRng) | 104.516 ns | 0.5099 ns | 0.4258 ns | - | - |
| Ulid.NewUlid(SimpleMonotonicUlidRng) | 51.985 ns | 0.3772 ns | 0.3344 ns | - | - |
| Ulid.NewUlid(CSMonotonicUlidRng) | 52.000 ns | 0.1184 ns | 0.1050 ns | - | - |
| Guid.Parse(string) | 100.885 ns | 1.2808 ns | 1.1354 ns | 0.0095 | 96 B |
| Ulid.Parse(string) | 199.476 ns | 3.2495 ns | 3.0396 ns | 0.0181 | 184 B |
| Guid.ToString() | 76.089 ns | 0.8230 ns | 0.6426 ns | 0.0095 | 96 B |
| Ulid.ToString() | 131.441 ns | 0.5919 ns | 0.4943 ns | 0.0079 | 80 B |
| 'new Guid(byte[])' | 9.341 ns | 0.1644 ns | 0.1538 ns | 0.0040 | 40 B |
| 'new Ulid(byte[])' | 11.045 ns | 0.1987 ns | 0.1951 ns | 0.0040 | 40 B |
| Guid.ToByteArray() | 65.470 ns | 0.1393 ns | 0.1163 ns | 0.0039 | 40 B |
| Ulid.ToByteArray() | 111.239 ns | 0.9540 ns | 0.7966 ns | 0.0038 | 40 B |
| Ulid.ToGuid() | 106.292 ns | 0.2446 ns | 0.2043 ns | - | - |
| 'new Ulid(Guid)' | 65.200 ns | 0.2050 ns | 0.1712 ns | - | - |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on NUlid:
| Package | Downloads |
|---|---|
|
Farsica.Framework
Asp.net Core Application Framework |
|
|
NidRpc
Library for internal RPC on FR22 SmartReader |
|
|
LeadSoft.Common.GlobalDomain
LeadSoft® Global Domain reúne classes e métodos que facilitam o dia-a-dia dos desenvolvedores .net. |
|
|
FormCMS
AI powered CMS |
|
|
CA.Blocks.DataAccess.Extensions.Translators.NUlid
Package Description |
Showing the top 6 popular GitHub repositories that depend on NUlid:
| Repository | Stars |
|---|---|
|
1Remote/1Remote
One Remote Access Manager to Rule Them All
|
|
|
Cysharp/Ulid
Fast .NET C# Implementation of ULID for .NET and Unity.
|
|
|
platformplatform/PlatformPlatform
A platform designed for building enterprise-grade, multi-tenant products using Azure, .NET, React, TypeScript, Infrastructure as Code, etc.
|
|
|
formcms/formcms
AI Agent: Open-source headless CMS built with ASP.NET Core (C#) and React, featuring REST APIs, GraphQL, and a GrapesJS page designer.
|
|
|
nnecrkvenuOX/formcms
AI Agent: Open-source headless CMS built with ASP.NET Core (C#) and React, featuring REST APIs, GraphQL, and a GrapesJS page designer.
|
|
|
valentinajemuovic/banking-kata-dotnet
Banking Kata (.NET)
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.7.3 | 437,949 | 5/16/2025 |
| 1.7.2 | 658,573 | 3/7/2024 |
| 1.7.1 | 722,590 | 8/30/2022 |
| 1.7.0 | 221,692 | 1/14/2022 |
| 1.5.0 | 528,737 | 7/9/2020 |
| 1.4.1 | 476,772 | 7/16/2019 |
| 1.4.0 | 114,733 | 5/24/2019 |
| 1.3.2 | 27,275 | 11/5/2018 |
| 1.3.1 | 12,291 | 2/24/2018 |
| 1.2.0 | 11,194 | 2/9/2017 |
| 1.1.0 | 3,015 | 8/4/2016 |
| 1.0.0 | 3,388 | 8/4/2016 |
| 0.9.0-rc | 2,658 | 8/4/2016 |