Not sure if your System.Random is that great, but you could combine with a much better Cryptopgraphy scheme. 10 of your characters and 40 of better...
Here it is in Linqpad
example : yours generates h0UcVayzu2
the other better one generates LyR7SUYZ-ZPll36wzGI5kMPamKtyXV_rN0Ax6iZG
Combined is then 50 characters
h0UcVayzu2LyR7SUYZ-ZPll36wzGI5kMPamKtyXV_rN0Ax6iZG
Code:
void Main()
{
var x = RandomString(10);
x.Dump();
var y = Example.GenerateIdentifier(40);
y.Dump();
var z = x + y;
z.Dump();
}
public static string RandomString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ=abcdefghijklmnopqrstuvwxyz0123456789";
var random = new Random();
return new string(Enumerable.Repeat(chars, length)
.Select(s => s[random.Next(s.Length)]).ToArray());
}
public class Example {
static readonly char[] AvailableCharacters = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'
};
internal static string GenerateIdentifier(int length) {
char[] identifier = new char[length];
byte[] randomData = new byte[length];
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider()) {
rng.GetBytes(randomData);
}
for (int idx = 0; idx < identifier.Length; idx++) {
int pos = randomData[idx] % AvailableCharacters.Length;
identifier[idx] = AvailableCharacters[pos];
}
return new string(identifier);
}
}