using System.Security.Cryptography;
public static void Main()
Console.WriteLine(GenerateRandomString(10));
Console.WriteLine(GenRandomStrings(10));
private static string GenerateRandomString(int length)
var random = new Random();
var allowedChars = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789";
var newPassword = string.Empty;
for (int i = 0; i < length; i++)
newPassword += allowedChars[random.Next(allowedChars.Length)];
private static string GenRandomStrings(int strLen)
var result = string.Empty;
using (var gen = new RNGCryptoServiceProvider())
while (result.Length < strLen)
gen.GetNonZeroBytes(data);
if (code > 48 && code < 57 ||
code > 65 && code < 90 ||
result += Convert.ToChar(code);