C# Random NextBytes
Description
Random NextBytes
fills the elements of a specified array
of bytes with random numbers.
Syntax
Random.NextBytes
has the following syntax.
public virtual void NextBytes(
byte[] buffer
)
Parameters
Random.NextBytes
has the following parameters.
buffer
- An array of bytes to contain random numbers.
Returns
Random.NextBytes
method returns
Example
The following example demonstrates how to use the NextBytes method to fill an array of bytes with random byte values.
using System;/*from w w w. ja va 2 s. c o m*/
public class Example
{
public static void Main()
{
Random rnd = new Random();
Byte[] b = new Byte[10];
rnd.NextBytes(b);
for (int i = 0; i <= b.GetUpperBound(0); i++)
Console.WriteLine("{0}: {1}", i, b[i]);
}
}
The code above generates the following result.