語言

RandomNumberGenerator.GetInt32 方法

定義

利用密碼學上強的隨機數生成器生成介於 0(含)與指定排他上限之間的隨機整數。

多載

名稱 Description
GetInt32(Int32)

利用密碼學上強的隨機數生成器生成介於 0(含)與指定排他上限之間的隨機整數。

GetInt32(Int32, Int32)

利用密碼學強隨機數產生器,生成指定包容性下界與指定排他上限之間的隨機整數。

GetInt32(Int32)

來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
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)

來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
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負值。

適用於