Skip to content

A csharp library to generate short id's. they can be used as primary keys or unique identifiers

License

Notifications You must be signed in to change notification settings

bolorundurowb/shortid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

shortid 🆔

Build Status License: MIT NuGet Version Coverage Status


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 GenerationOptions(useNumbers: true);
string id = ShortId.Generate(options);
// Example output: O_bBY-YUkJg

Exclude Special Characters

var options = new GenerationOptions(useSpecialCharacters: false);
string id = ShortId.Generate(options);
// Example output: waBfk3z

Specify ID Length

var options = new GenerationOptions(length: 9);
string id = ShortId.Generate(options);
// Example output: M-snXzBkj

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! 🚀

About

A csharp library to generate short id's. they can be used as primary keys or unique identifiers

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages