Generate 32 bytes of random data : RandomNumberGenerator « Security « C# / CSharp Tutorial






using System;
using System.Security.Cryptography;

class MainClass
{
    public static void Main() {
        byte[] number = new byte[32];
        
        RandomNumberGenerator rng = RandomNumberGenerator.Create();
        
        
        rng.GetBytes(number);
        
        // Display the random number.
        Console.WriteLine(BitConverter.ToString(number));

    }
}
B9-33-DA-50-FB-D0-A7-7A-6D-7C-12-A7-47-A5-FE-45-F0-E0-DC-87-AE-27-CE-C0-76-D5-85-5C-DF-7D-4A-82








35.8.RandomNumberGenerator
35.8.1.Generate 32 bytes of random data
35.8.2.Cryptographically sound random numbers