RandomNumberGenerator.GetInt32 方法

定义

重载

名称 说明
GetInt32(Int32)

使用加密强随机数生成器生成介于 0(非独占)和指定独占上限之间的随机整数。

GetInt32(Int32, Int32)

使用加密强随机数生成器在指定的非独占下限和指定的独占上限之间生成随机整数。

GetInt32(Int32)

Source:
RandomNumberGenerator.cs
Source:
RandomNumberGenerator.cs
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
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

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

两者都允许 fromInclusive 负值和 toExclusive

适用于