using System.Security.Cryptography;
public static void Main()
Console.WriteLine(GenerateRandomToken());
public static string GenerateRandomToken(int tokenSize = 10)
string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
using (var crypto = new RNGCryptoServiceProvider())
var data = new byte[tokenSize];
byte[] smallBuffer = null;
int maxRandom = byte.MaxValue - ((byte.MaxValue + 1) % chars.Length);
var result = new char[tokenSize];
for (int i = 0; i < tokenSize; i++)
smallBuffer = new byte[1];
crypto.GetBytes(smallBuffer);
result[i] = chars[v % chars.Length];
return new string(result);