shortid 2.0.0

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

Install-Package shortid -Version 2.0.0
dotnet add package shortid --version 2.0.0
<PackageReference Include="shortid" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add shortid --version 2.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

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 id's generated. I have tested the application generating 200000 ids without duplicates.

How to use

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

Install-Package shortid

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

using shortid;

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

To generate a unique id of any length between 7 and 14, 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 a boolean indicating your preference.

string id = ShortId.Generate(true);
// id = O_bBY-YUkJg

If you do not want special characters i.e _ and - in your generated id, then call the Generate method with two boolean parameters, the first indicating whether or not you want numbers and the second indicating whether or not you want special characeters.

string id = ShortId.Generate(true, false);
// id = waBfk3z

If you want to specify the length of the generated id, call the Generate method with an integer parameter which is the desired length.

string id = ShortId.Generate(8);
// id = M-snXzBk

If you want to control the type of id generated by specifying whether you want numbers, special characters and the length, call the Generate method and pass three parameters, the first a boolean stating whether you want numbers, the second a boolean stating whether you want special characters, the last a number indicating your length preference.

string id = ShortId.Generate(true, false, 12);
// id = VvoCDPazES_w

NOTE: when specifying the desired length, shorter lengths increase the possibility thata duplicate id would be generated

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 number null, an empty string or whitespace. Also, all whitespace characters would be removed, finally the character set cannot be less than 20 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

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 id's generated. I have tested the application generating 200000 ids without duplicates.

How to use

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

Install-Package shortid

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

using shortid;

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

To generate a unique id of any length between 7 and 14, 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 a boolean indicating your preference.

string id = ShortId.Generate(true);
// id = O_bBY-YUkJg

If you do not want special characters i.e _ and - in your generated id, then call the Generate method with two boolean parameters, the first indicating whether or not you want numbers and the second indicating whether or not you want special characeters.

string id = ShortId.Generate(true, false);
// id = waBfk3z

If you want to specify the length of the generated id, call the Generate method with an integer parameter which is the desired length.

string id = ShortId.Generate(8);
// id = M-snXzBk

If you want to control the type of id generated by specifying whether you want numbers, special characters and the length, call the Generate method and pass three parameters, the first a boolean stating whether you want numbers, the second a boolean stating whether you want special characters, the last a number indicating your length preference.

string id = ShortId.Generate(true, false, 12);
// id = VvoCDPazES_w

NOTE: when specifying the desired length, shorter lengths increase the possibility thata duplicate id would be generated

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 number null, an empty string or whitespace. Also, all whitespace characters would be removed, finally the character set cannot be less than 20 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 thread safety and minimum length

  • .NETFramework 4.0

    • No dependencies.
  • .NETFramework 4.5

    • No dependencies.
  • .NETStandard 1.3

    • No dependencies.

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
2.0.0 107,456 3/9/2018
1.0.4 2,532 2/6/2018
1.0.3 4,895 11/27/2017
1.0.2 5,196 7/5/2017
1.0.1 335 6/13/2017
1.0.0 333 6/10/2017