SecureRandom random = new SecureRandom(); byte[] byteArray = new byte[1]; random.NextBytes(byteArray);
SecureRandom random = new SecureRandom(); int max = 10; int min = 1; int randomNumber = random.Next(min, max);
SecureRandom random = new SecureRandom(); int length = 5; const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; string randomString = new string(Enumerable.Repeat(chars, length) .Select(s => s[random.Next(s.Length)]) .ToArray());In the above examples, we have used the SecureRandom class to generate random numbers and bytes. These examples are used to generate random data for different purposes such as generating session IDs, passwords, and cryptographic keys. The SecureRandom class is part of the Bouncy Castle Crypto package library.