.NET library to generate random strings. This package is based on the original RandomString4Net package by Lakhya Jyoti Nath.
$ dotnet add package StuceSoftware.RandomStringGeneratorAuthors :
Jeff Shergalis
Lakhya Jyoti Nath (ljnath)
Date : September 2020 - October 2024
StuceSoftware.RandomStringGenerator is a library developed in C# to generate random strings of from various categories.
It is fast and suports string generation of various length. It is parameterized to generate both a single or a list of random strings.
Random strings can be of types lowercase, uppercase, numbers and symbols. It also allows you to generate random string with only a
subset of symbols from the supported list. It is an ideal library for use in projects such as:
These types are defined by an enum CharClasses which has the [Flags] attribue, making it easy to combine the different classes.
Breaking Change :rotating_light:
The switch to a [Flags] enum is a breaking change in version 2.0
NuGet Package StuceSoftware.RandomStringGenerator
Install-Package StuceSoftware.RandomStringGeneratorusing StuceSoftware.RandomStringGenerator;
// generating one random string from lowercase alphabets
var randomString = RandomString.GetString(CharClasses.Lowercase);
System.Console.WriteLine(randomString);
// generating 100 random strings using both upper and lower case alphabet, numbers and all supported symbols
var randomAlphaNumbericStrings = RandomString.GetStrings(
CharClasses.Lowercase | CharClasses.Uppercase | CharClasses.Numbers | CharClasses.Symbols, 100);
foreach (string s in randomAlphaNumbericStrings)
System.Console.WriteLine(s);
// generating 200 random string using uppercase alphabet and custom symbols
var randomAlphabetWithCustomSymbols = RandomString.GetStrings(CharClasses.Uppercase, 200, "/+*-");
foreach (string s in randomAlphabetWithCustomSymbols)
System.Console.WriteLine(s);
// generating 1000 true random strings of length 20 using uppercase alphabet with custom symbols
var trueUniqueRandomStrings = RandomString.GetStrings(CharClasses.Uppercase, 1000, 20, "/+*-", false, true);
foreach (string s in trueUniqueRandomStrings)
System.Console.WriteLine(s);
// generating 100 random strings using both upper and lowercase alphabet, numbers and custom symbols
var randomAlphabetWithCustomSymbols = RandomString.GetStrings(CharClasses.Lowercase | CharClasses.Uppercase | CharClasses.Numbers, 100, "/+*-", forceOccuranceOfEachType: true);
foreach (string s in randomAlphabetWithCustomSymbols)
System.Console.WriteLine(s);Note :eyes:
As of version 2.0, if custom symbols are defined, there is no need to specify the symbol character class (CharClasses.Symbols),
this is assumed when custom symbols are provided
If you find this library helpful, please give it a star. Thanks in advance!
Copyright © 2024 Stuce Software Solutions under the MIT License.