RandomExtensionsNextInt32(Random, Int32, Int32, Boolean) Method

Returns a random 32-bit signed integer that is within a specified range.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.1.0
C#
public static int NextInt32(
	this Random random,
	int minValue,
	int maxValue,
	bool inclusiveUpperBound = false
)

Parameters

random  Random
The Random instance to use.
minValue  Int32
The inclusive lower bound of the random number returned.
maxValue  Int32
The upper bound of the random number returned. Must be greater or equal to minValue.
inclusiveUpperBound  Boolean  (Optional)
to allow that the generated value is equal to maxValue; otherwise, . This parameter is optional.
Default value: .

Return Value

Int32
A 64-bit signed integer that is greater than or equal to minValue and less than or equal to maxValue. If inclusiveUpperBound is , then maxValue is an exclusive upper bound; however, if minValue equals maxValue, maxValue is returned.

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 is .
ArgumentOutOfRangeExceptionmaxValue is less than minValue.

See Also