UniqueIdGenerator.Net 2.2.0

dotnet add package UniqueIdGenerator.Net --version 2.2.0
                    
NuGet\Install-Package UniqueIdGenerator.Net -Version 2.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UniqueIdGenerator.Net" Version="2.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UniqueIdGenerator.Net" Version="2.2.0" />
                    
Directory.Packages.props
<PackageReference Include="UniqueIdGenerator.Net" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add UniqueIdGenerator.Net --version 2.2.0
                    
#r "nuget: UniqueIdGenerator.Net, 2.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package UniqueIdGenerator.Net@2.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=UniqueIdGenerator.Net&version=2.2.0
                    
Install as a Cake Addin
#tool nuget:?package=UniqueIdGenerator.Net&version=2.2.0
                    
Install as a Cake Tool

Unique Id Generator

C# implementation of Twitter's Snowflake. A Generator can create sequentially unique IDs with a length of 8 bytes.
The ID consists of a timestamp (milliseconds since specific start date), a generator id and a sequence.

This is the default configuration:

  • 41 bits for timestamp in milliseconds (can vary from 40 to 45)
  • 10 bits for generator id (can vary from 0 to 10)
  • 13 bits for sequence (can vary from 12 to 20)

You can change this default values to gain more performance on a single process (more sequence-bits) or more performance in a cluster (more generator-bits).
With the default configuration you can create 1024 different generators. Each generator can create up to 8192 unique IDs per millisecond for 69 years.

Usage

First, grab the assembly from NuGet.

// Create a new instance of the generator
var generator = new Generator(machineId, projectStartDate);
    
// get a new id
generator.Next();

Performance measurement

Environment:

  • Intel Core i7-3740QM (2.7GHz)
  • 8GB RAM
  • Microsoft Windows 8.0 x64
  • Default configuration (41/10/13)

Single generator

Duration to generate 10'000'000 ids: 1'847 ms
Number of ids generated in 1 ms: 5'414
Number of ids generated in 1 s: 5'414'185

4 generators

Duration to generate 20'000'000 ids: 2'506 ms
Number of ids generated in 1 ms: 7'980
Number of ids generated in 1 s: 7'980'845

8 generators

Duration to generate 8'000'000 ids: 802 ms
Number of ids generated in 1 ms: 9'975
Number of ids generated in 1 s: 9'975'062

16 generators

Duration to generate 16'000'000 ids: 1'569 ms
Number of ids generated in 1 ms: 10'197
Number of ids generated in 1 s: 10'197'578

32 generators

Duration to generate 16'000'000 ids: 1'657 ms
Number of ids generated in 1 ms: 9'656
Number of ids generated in 1 s: 9'656'004

64 generators

Duration to generate 12'800'000 ids: 1'510 ms
Number of ids generated in 1 ms: 8'476
Number of ids generated in 1 s: 8'476'821

License

Developed by Michael Schuler under the MIT License

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0 134 9/10/2025
2.1.0 139 9/10/2025