Muokkaa

Jaa


RandomNumberGenerator.GetBytes Method

Definition

Fills an array of bytes with a cryptographically strong random sequence of values.

Overloads

GetBytes(Span<Byte>)

Fills a span with cryptographically strong random bytes.

GetBytes(Byte[], Int32, Int32)

Fills the specified byte array with a cryptographically strong random sequence of values.

GetBytes(Byte[])

When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of values.

GetBytes(Int32)

Creates an array of bytes with a cryptographically strong random sequence of values.

GetBytes(Span<Byte>)

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

Fills a span with cryptographically strong random bytes.

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))

Parameters

data
Span<Byte>

The span to fill with cryptographically strong random bytes.

See also

Applies to

GetBytes(Byte[], Int32, Int32)

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

Fills the specified byte array with a cryptographically strong random sequence of values.

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)

Parameters

data
Byte[]

The array to fill with cryptographically strong random bytes.

offset
Int32

The index of the array to start the fill operation.

count
Int32

The number of bytes to fill.

Exceptions

data is null.

offset or count is less than 0

offset plus count exceeds the length of data.

Applies to

GetBytes(Byte[])

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

When overridden in a derived class, fills an array of bytes with a cryptographically strong random sequence of values.

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())

Parameters

data
Byte[]

The array to fill with cryptographically strong random bytes.

Examples

The following example creates a random sequence 100 bytes long and stores it in random.

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

RandomNumberGenerator^ rng = RandomNumberGenerator::Create();
rng->GetBytes( random ); // The array is now filled with cryptographically strong random bytes.
byte[] random = new byte[100];

using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
{
    rng.GetBytes(random); // The array is now filled with cryptographically strong random bytes.
}
Dim random() As Byte = New Byte(100) {}
       
Using rng As RandomNumberGenerator = RandomNumberGenerator.Create()
   rng.GetBytes(random) ' bytes in random are now random
End Using

Remarks

The length of the byte array determines how many random bytes are produced.

See also

Applies to

GetBytes(Int32)

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

Creates an array of bytes with a cryptographically strong random sequence of values.

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()

Parameters

count
Int32

The number of bytes of random values to create.

Returns

Byte[]

An array populated with cryptographically strong random values.

Exceptions

count is less than zero.

Applies to