shortid 3.0.0

A library that generates random identifiers from 7 to 14 characters. Identifiers generated can be used as primary keys for databases or unique identifiers.

Install-Package shortid -Version 3.0.0
dotnet add package shortid --version 3.0.0
<PackageReference Include="shortid" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add shortid --version 3.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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();

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();

Release Notes

-
- add in further restrictions to maintain uniqueness

  • .NETStandard 1.1

    • No dependencies.
  • .NETStandard 1.3

    • No dependencies.
  • .NETStandard 1.6

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (7)

Showing the top 5 NuGet packages that depend on shortid:

Package Downloads
kotori-core
Kotori core library.
Programatica.Framework.Mvc
Development framework accelarator
fc-messaging-utils
Package Description
OscTree
A tree concept for sending and receiving OSC Messages
fc-corelation-id-manager
Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
3.0.0 9,511 8/27/2020
2.0.4 735 8/26/2020
2.0.3 24,834 7/4/2020
2.0.2 1,003 6/29/2020
2.0.1 42,167 3/26/2020
2.0.0 239,621 3/9/2018
1.0.4 3,011 2/6/2018
1.0.3 7,214 11/27/2017
1.0.2 5,390 7/5/2017
1.0.1 455 6/13/2017
1.0.0 460 6/10/2017