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! πŸš€

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy