A .NET library for generating Time-Sorted Unique Identifiers (TSID). Compatible with .NET Standard 2.0/.NET Standard 2.1.
It brings together ideas from Twitter's Snowflake and ULID Spec.
In summary:
- Sorted by generation time;
- Can be stored as an integer of 64 bits;
- Can be stored as a string of 13 chars;
- String format is encoded to Crockford's base32;
- String format is URL safe, is case insensitive, and has no hyphens;
- Shorter than UUID, ULID and KSUID.
This library is a port of the Java code found here.
It is highly recommended to consult first the original Java code before using this library, in terms of usage and performance.
Create a TSID:
Tsid tsid = TsidCreator.GetTsid();
Create a TSID as long
:
long number = TsidCreator.GetTsid().ToLong(); // 38352658567418872
Create a TSID as String
:
string string = TsidCreator.GetTsid().ToString(); // 01226N0640J7Q
The TSID generator is thread-safe.