RandomNumberGenerator.GetBytes Method (Byte[])

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

public abstract void GetBytes(
	byte[] data
)

Parameters

data
Type: System.Byte[]

The array to fill with cryptographically strong random bytes.

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

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

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.

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: