• Stars
    star
    218
  • Rank 175,807 (Top 4 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

shortid

Build Status License: MIT NuGet Badge Coverage Status

About ShortId

A CSharp library to generate completely random short id's. They can be used as primary keys or unique identifiers. This library is different in that you can specify the length of the ids to be generated. This library is thread-safe and can generate millions of unique ids across multiple threads.

Getting Started

To make use of the shortid, add it to your project via the Nuget package manager UI or console via this command:

Package Manager

Install-Package shortid

.NET CLI

> dotnet add package shortid

PackageReference

<PackageReference Include="shortid" />

Usage

Add the following using command to the top of your csharp code file:

using shortid;
using shortid.Configuration;

This gives your code access the classes and methods of the shortid namespace.

To generate a unique id of any length between 8 and 15, you call the Generate method without parameters.

string id = ShortId.Generate();
// id = KXTR_VzGVUoOY

If you want to include numbers in the generated id, then you call the Generate method with options indicating your preference.

var options = new GenerationOptions(useNumbers: true);
string id = ShortId.Generate(options);
// id = O_bBY-YUkJg

If you do not want special characters i.e _ and - in your generated id, then call the Generate method with options indicating your preferences.

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

If you want to specify the length of the generated id, call the Generate method with options indicating your preferences.

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

Customize ShortId

ShortId has several features that help with customizing the ids generated. Characters sets can be introduced and the random number generator can be seeded.

To change the character set in use, run the following:

string characters = "β’Άβ’·β’Έβ’Ήβ’Ίβ’»β’Όβ’½β’Ύβ’Ώβ“€β“β“‚β“ƒβ“„β“…β“†β“‡β“ˆβ“‰β“Šβ“‹β“Œβ“β“Žβ“β“β“‘β“’β““β“”β“•β“–β“—β“˜β“™β“šβ“›β“œβ“β“žβ“Ÿβ“ β“‘β“’β“£β“€β“₯ⓦⓧⓨⓩ①⑑⑒④⑀β‘₯⑦⑧⑨⑩β‘ͺβ‘«"; //whatever you want;
ShortId.SetCharacters(characters);

NOTE: the new character set must not be null, an empty string or whitespace. Also, all whitespace and duplicate characters would be removed, finally the character set cannot be less than 50 characters.

ShortId also allows the seed for the random number generator to be set.

To set the seed, run the following:

int seed = 1939048828;
ShortId.SetSeed(seed);

Finally, ShortId allows for all customizations to be reset using the following:

ShortId.Reset();

More Repositories

1

dotenv.net

A library to read .env files in a .NET Core environment
C#
211
star
2

Open-Exam-Suite

This project seeks to create an open source exam designer and simulator that will be solace for those wanting to take any simulated examinations.
C#
144
star
3

vCardLib

A .NET standard library for reading vCard files
C#
22
star
4

git-aliases-for-windows

πŸ’― Add oh-my-zsh-like git aliases to your command prompt
Batchfile
19
star
5

moment.net

Basically as much of a dot net port of moment.js as necessary
C#
19
star
6

dotnetANPR

A number plate recognition library for .NET based off javaanpr
C#
14
star
7

aspnetcore-httpclientextensions

Json verb extensions for ASP.NET core HttpClient
C#
9
star
8

meerkat

A library aiming to implement functionality similar to NodeJS's mongoose
C#
7
star
9

VCF-Reader

vcf file reader
C#
5
star
10

logly

A HTTP Request and Response logger for ASP.NET Core
C#
5
star
11

firenotes-api

A .NET Core RESTful Web API to power the fire πŸ”₯ notes app
C#
4
star
12

firenotes

A simple notes app that utilizes Googles firebase for authentication and storage. Built for Android and iOS using Xamarin Forms
C#
4
star
13

PostgresConnString.NET

A library to handle postgres connection strings
C#
3
star
14

whatsapp-web-duo

An Avalonia UI cross-platform app to enable users make use of multiple WhatsApp accounts on their desktops
C#
2
star
15

millify-dotnet

A dotnet library to convert long numbers to pretty, human-readable strings.
C#
2
star
16

emoji-uid-dotnet

A .NET port of the NodeJS emoji-uid project
C#
2
star
17

foursquare-vgc-projects

A repo to hold the foursquare VGC projects
C#
1
star
18

no-comment

A browser plugin that can show or hide comments from social platforms such as YouTube and Facebook as we deserve to view content and form our opinions without bias
JavaScript
1
star
19

NETCover

A code coverage tool for C#
C#
1
star
20

geo-info-service

An open source free web service for retrieving continent, country and state/province info
CSS
1
star
21

read-time-estimator

Estimate read times for HTML and Markdown articles
C#
1
star
22

autobackup

A tool that automates the backup process to external USB storage devices
C#
1
star
23

atheneum-app

A cross-platform app to help users manage their local libraries using Xamarin Forms
TypeScript
1
star
24

crypto-stats

A demo app for Xamarin Android, iOS and Forms that just displays current coin stats
C#
1
star
25

consolify

A rust library to print out any given text in large blocks.
Rust
1
star
26

mongo-url-parser

A small library to parse mongo url strings to extract the database name
C#
1
star
27

open-exam-suite-upgrade-tool

The upgrade tool for older .oef files
C#
1
star
28

dotnet-credentials-in-url-parser

C#
1
star
29

PropertyConfig

This library is developed to provide similar functionality to Java's java.util.Properties class.
C#
1
star