RandomExtensionsNextString(Random, Int32, Int32, Char) 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: 7.0.0-rc.1
C#
public static string NextString(
	this Random random,
	int minLength,
	int maxLength,
	char[] 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  Char
An array 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 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