/StringId

Generate random string Id values, with ability to specify lengths and combinations of upper, lower, numeric, and special characters

Primary LanguageC#MIT LicenseMIT

Nuget

Use this to create random string Ids of a specified length and combination of character ranges. For example:

var id = StringId.New(9, StringIdRanges.Lower | StringIdRanges.Numeric);

Might produce 5m65urzga

You can also chain several random strings together like this:

string result = new StringIdBuilder()
                  .Add(4, StringIdRanges.Upper)
                  .Add("-")
                  .Add(4, StringIdRanges.Upper)
                  .Add("-")
                  .Add(4, StringIdRanges.Upper)
                  .Build();

Might produce KRHD-OZBB-CVUU. This capability was inspired by Keywielder.

There's also a NewPassword method that generates a high-quality 16-character password:

var pwd = StringId.NewPassword();

Might produce BBnHMLju8>8q!cTT.

The unit test for Id uniqueness achieves 1 million unique 9-character Ids. You can of course create Ids of any length.

The original idea for this came from a blog post by Scott Lilly, but I adapted it for creating random strings.