System.Random.NextBytes Method

Fills the elements of a specified array of bytes with random numbers.

Syntax

public virtual void NextBytes (byte[] buffer)

Parameters

buffer
An array of bytes to contain random numbers.

Exceptions

TypeReason
ArgumentNullException buffer is a null reference.

Remarks

Each element of the array of bytes is set to a random number greater than or equal to zero, and less than or equal to byte.MaxValue.

To generate a cryptographically secured random number suitable for creating a random password, for example, use a method such as System.Security.Cryptography.RNGCryptoServiceProvider.GetBytes(Byte[]).

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0