System.Random.Next Method

Returns a nonnegative random integer that is less than the specified maximum.

Syntax

public virtual int Next (int maxValue)

Parameters

maxValue
The exclusive upper bound of the random number to be generated. maxValue must be greater than or equal to zero.

Returns

A 32-bit signed integer greater than or equal to zero, and less than maxValue; that is, the range of return values ordinarily includes zero but not maxValue. However, if maxValue equals zero, maxValue is returned.

Exceptions

TypeReason
ArgumentOutOfRangeException maxValue is less than zero.

Remarks

Operation
As described above.

Note to Inheritors
Override this method to customize the algorithm used to generate the return value.

Usage
Use this method to generate a psuedo-random number less than the specified maximum value.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0