shortid 5.0.0
dotnet add package shortid --version 5.0.0
NuGet\Install-Package shortid -Version 5.0.0
<PackageReference Include="shortid" Version="5.0.0" />
<PackageVersion Include="shortid" Version="5.0.0" />
<PackageReference Include="shortid" />
paket add shortid --version 5.0.0
#r "nuget: shortid, 5.0.0"
#:package shortid@5.0.0
#addin nuget:?package=shortid&version=5.0.0
#tool nuget:?package=shortid&version=5.0.0
shortid π
About ShortId π
ShortId is a lightweight and efficient C# library designed to generate completely random, short, and unique identifiers. These IDs are perfect for use as primary keys, unique identifiers, or any scenario where you need a compact, random string. π―
What sets ShortId apart is its flexibilityβyou can specify the length of the IDs (between 8 and 15 characters) and customize the character set. Itβs also thread-safe, making it ideal for high-performance applications that require generating millions of unique IDs across multiple threads. πͺ
Getting Started π
Installation π¦
You can add ShortId to your project using one of the following methods:
Package Manager
Install-Package shortid
.NET CLI
dotnet add package shortid
PackageReference
<PackageReference Include="shortid" />
Usage π οΈ
Add the Namespace
First, include the ShortId namespace in your code:
using shortid;
using shortid.Configuration;
Generate a Random ID
To generate a random ID of default length (between 8 and 15 characters), simply call the Generate method:
string id = ShortId.Generate();
// Example output: KXTR_VzGVUoOY
Customize ID Generation π¨
ShortId provides several options to tailor the generated IDs to your needs:
Include Numbers
var options = new ShortIdOptions(useNumbers: true);
string id = ShortId.Generate(options);
// Example output: O_bBY-YUkJg
Exclude Special Characters
var options = new ShortIdOptions(useSpecialCharacters: false);
string id = ShortId.Generate(options);
// Example output: waBfk3z
Specify ID Length
var options = new ShortIdOptions(length: 9);
string id = ShortId.Generate(options);
// Example output: M-snXzBkj
Generate Sequential IDs
For scenarios where you need IDs to be monotonic (i.e., each ID is greater than the previous one), you can enable sequential ID generation:
var options = new ShortIdOptions(generateSequential: true);
string id = ShortId.Generate(options);
// Example output: 00000r_v
When this option is enabled, the first 6 characters of the ID represent a Base85 encoded timestamp, followed by random characters to complete the requested length.
Customize ShortId ποΈ
ShortId allows you to fully customize the character set and even seed the random number generator for reproducible results.
Change the Character Set
You can define your own character set for ID generation:
string characters = "βΆβ·βΈβΉβΊβ»βΌβ½βΎβΏββββββ
βββββββββββββββββββββββββββ β‘β’β£β€β₯β¦β§β¨β©β β‘β’β£β€β₯β¦β§β¨β©βͺβ«"; // Custom character set
ShortId.SetCharacters(characters);
Note:
- The character set must contain at least 50 unique characters.
- Duplicate and whitespace characters are automatically removed.
Set a Random Seed
For reproducible results, you can set a seed for the random number generator:
int seed = 1939048828;
ShortId.SetSeed(seed);
Reset Customizations
To reset all customizations (character set, seed, etc.) to their defaults, use the Reset method:
ShortId.Reset();
Why Use ShortId? π
- Flexible Length: Generate IDs between 8 and 15 characters long.
- Customizable: Use your own character set or exclude special characters.
- Thread-Safe: Perfect for multi-threaded applications.
- Lightweight: Minimal overhead, maximum performance.
- Easy to Use: Simple API with just a few methods.
License π
ShortId is licensed under the MIT License. See the LICENSE file for more details.
Get Started Today! π
Whether you need unique IDs for database keys, URLs, or any other purpose, ShortId has you covered. Install the package, follow the examples, and start generating unique IDs in seconds! β±οΈ
Happy Coding! π
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- System.Memory (>= 4.6.3)
NuGet packages (15)
Showing the top 5 NuGet packages that depend on shortid:
| Package | Downloads |
|---|---|
|
Dmaal.Core.Helper
Package Description |
|
|
kotori-core
Kotori core library. |
|
|
Wabbajack.Paths.IO
Package Description |
|
|
Programatica.Framework.Mvc
Development framework accelarator |
|
|
Yamf.Multitenancy
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on shortid:
| Repository | Stars |
|---|---|
|
wabbajack-tools/wabbajack
An automated Modlist installer for various games.
|
|
|
replaysMike/Binner
Open source parts inventory system for makers, electronics hobby, and professional engineers
|
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.0 | 2,655 | 3/7/2026 |
| 4.0.0 | 4,002,857 | 4/21/2022 |
| 3.0.2 | 2,124 | 11/5/2023 |
| 3.0.1 | 1,288,260 | 4/11/2021 |
| 3.0.0 | 422,446 | 8/27/2020 |
| 2.0.4 | 46,151 | 8/26/2020 |
| 2.0.3 | 67,472 | 7/4/2020 |
| 2.0.2 | 9,311 | 6/29/2020 |
| 2.0.1 | 226,527 | 3/26/2020 |
| 2.0.0 | 588,727 | 3/9/2018 |
| 1.0.4 | 6,825 | 2/6/2018 |
| 1.0.3 | 11,904 | 11/27/2017 |
| 1.0.2 | 8,129 | 7/5/2017 |
| 1.0.1 | 2,838 | 6/13/2017 |
| 1.0.0 | 4,335 | 6/10/2017 |
- add support for monotonic/sequential id generation
- move the generation options to the package root