Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0330 High-security random

using System; using System.Numerics; class Sample { public static void Main() { var rand = System.Security.Cryptography.RandomNumberGenerator.Create(); byte[] bytes = new byte[32]; rand.GetBytes(bytes); int i = BitConverter.ToInt32(bytes, 0); Console.WriteLine(i); } } The output: 1208100698