RandomNumberGenerator.GetBytes 方法

定義

在位元組陣列中填入在密碼編譯方面的強式隨機值序列。

多載

GetBytes(Span<Byte>)

填入密碼編譯強式隨機位元組的範圍。

GetBytes(Byte[], Int32, Int32)

將在密碼編譯方面強式的隨機值序列填入指定的位元組陣列。

GetBytes(Byte[])

在衍生類別中覆寫時,將在密碼編譯方面強式的隨機值序列填入位元組陣列。

GetBytes(Int32)

建立具有密碼編譯強式隨機值序列的位元組陣列。

GetBytes(Span<Byte>)

來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs

填入密碼編譯強式隨機位元組的範圍。

public:
 virtual void GetBytes(Span<System::Byte> data);
public virtual void GetBytes (Span<byte> data);
abstract member GetBytes : Span<byte> -> unit
override this.GetBytes : Span<byte> -> unit
Public Overridable Sub GetBytes (data As Span(Of Byte))

參數

data
Span<Byte>

要填入密碼編譯強式隨機位元組的範圍。

另請參閱

適用於

GetBytes(Byte[], Int32, Int32)

來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs

將在密碼編譯方面強式的隨機值序列填入指定的位元組陣列。

public:
 virtual void GetBytes(cli::array <System::Byte> ^ data, int offset, int count);
public virtual void GetBytes (byte[] data, int offset, int count);
abstract member GetBytes : byte[] * int * int -> unit
override this.GetBytes : byte[] * int * int -> unit
Public Overridable Sub GetBytes (data As Byte(), offset As Integer, count As Integer)

參數

data
Byte[]

要將在密碼編譯方面強式的隨機位元組填入的陣列。

offset
Int32

要開始填入作業的陣列索引。

count
Int32

要填入的位元組數目。

例外狀況

datanull

offsetcount 小於 0

offset 加上 count 超過 data 的長度。

適用於

GetBytes(Byte[])

來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs

在衍生類別中覆寫時,將在密碼編譯方面強式的隨機值序列填入位元組陣列。

public:
 abstract void GetBytes(cli::array <System::Byte> ^ data);
public abstract void GetBytes (byte[] data);
abstract member GetBytes : byte[] -> unit
Public MustOverride Sub GetBytes (data As Byte())

參數

data
Byte[]

要將在密碼編譯方面強式的隨機位元組填入的陣列。

範例

下列範例會建立 100 個位元組的隨機序列,並將其儲存在 random 中。

array<Byte>^ random = gcnew array<Byte>(100);

//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider^ rng = gcnew RNGCryptoServiceProvider;
rng->GetBytes( random ); // The array is now filled with cryptographically strong random bytes.
byte[] random = new Byte[100];

//RNGCryptoServiceProvider is an implementation of a random number generator.
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
Dim random() As Byte = New Byte(100) {}
       
'RNGCryptoServiceProvider is an implementation of an RNG
Dim rng As New RNGCryptoServiceProvider()
rng.GetBytes(random) ' bytes in random are now random

備註

位元組陣列的長度會決定產生多少個隨機位元組。

另請參閱

適用於

GetBytes(Int32)

來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs
來源:
RandomNumberGenerator.cs

建立具有密碼編譯強式隨機值序列的位元組陣列。

public:
 static cli::array <System::Byte> ^ GetBytes(int count);
public static byte[] GetBytes (int count);
static member GetBytes : int -> byte[]
Public Shared Function GetBytes (count As Integer) As Byte()

參數

count
Int32

要建立之隨機值的位元組數目。

傳回

Byte[]

以密碼編譯強式隨機值填入的陣列。

例外狀況

count 小於零。

適用於