using System;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public void Main()
int l = 10;
string str = GenerateRandomString(l);
Console.WriteLine(str);
}
public string GenerateRandomString(int length)
if (length < 1)
return string.Empty;
string response;
var codeData = new byte[length];
using (var randomStringGenerator = new RNGCryptoServiceProvider())
randomStringGenerator.GetBytes(codeData);
Console.WriteLine(codeData.ToString());
response = Encoding.Default.GetString(codeData);
return response;