RandomNumberGenerator.GetInt32 方法

定义

重载

GetInt32(Int32)

使用加密型强随机数生成器生成介于 0(含)与指定上限(不含)之间的随机整数。

GetInt32(Int32, Int32)

使用加密型强随机数生成器生成介于指定下限(含)与指定上限(不含)之间的随机整数。

GetInt32(Int32)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

使用加密型强随机数生成器生成介于 0(含)与指定上限(不含)之间的随机整数。

public:
 static int GetInt32(int toExclusive);
public static int GetInt32 (int toExclusive);
static member GetInt32 : int -> int
Public Shared Function GetInt32 (toExclusive As Integer) As Integer

参数

toExclusive
Int32

随机范围的上限(不含)。

返回

介于 0(含)与 toExclusive(不含)之间的随机整数。

例外

toExclusive 参数小于或等于 0。

注解

上限是独占的,用于从数组、范围或列表传入长度值。 因为它是独占上限,因此此方法永远无法生成 Int32.MaxValue

此方法使用放弃和重试策略来避免简单模块化算术运算产生的低值偏差。

适用于

GetInt32(Int32, Int32)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs

使用加密型强随机数生成器生成介于指定下限(含)与指定上限(不含)之间的随机整数。

public:
 static int GetInt32(int fromInclusive, int toExclusive);
public static int GetInt32 (int fromInclusive, int toExclusive);
static member GetInt32 : int * int -> int
Public Shared Function GetInt32 (fromInclusive As Integer, toExclusive As Integer) As Integer

参数

fromInclusive
Int32

随机范围的下限(含)。

toExclusive
Int32

随机范围的上限(不含)。

返回

介于 fromInclusive(含)与 toExclusive(不含)之间的随机整数。

例外

toExclusive 参数小于或等于 fromInclusive 参数。

注解

上限是独占的,用于从数组、范围或列表传入长度值。 因为它是独占上限,因此此方法永远无法生成 Int32.MaxValue

此方法使用放弃和重试策略来避免简单模块化算术运算产生的低值偏差。

toExclusive都允许负fromInclusive值。

适用于