RandomExtensionsNextString(Random, Int32, Int32, String) Method

Returns a random String that has the length between the specified range and consists of the specified allowedCharacters.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static string NextString(
	this Random random,
	int minLength,
	int maxLength,
	string allowedCharacters
)

Parameters

random  Random
The Random instance to use.
minLength  Int32
The inclusive lower bound of the length of the returned string.
maxLength  Int32
The inclusive upper bound of the length of the returned string. Must be greater or equal to minLength.
allowedCharacters  String
A string containing the allowed characters. Recurring characters may appear in the result more frequently than others.

Return Value

String
A String value that has the length greater than or equal to minLength and less and less than or equal to maxLength and contains only the specified characters.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Random. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ArgumentNullExceptionrandom or allowedCharacters is .
ArgumentOutOfRangeExceptionminLength is less than 0 or maxLength is less than minLength
ArgumentExceptionallowedCharacters is empty.

See Also