public static string RandomString(this String str, int size, bool lowerCase)
{
StringBuilder builder = new StringBuilder();
Random random = new Random();
char ch;
for (int i = 0; i < size; i++)
{
ch = Convert.ToChar(Convert.ToInt32(Math.Floor(2 * random.NextDouble() + 28)));
builder.Append(ch);
}
if (lowerCase)
return builder.ToString().ToLower();
return builder.ToString();
}
* One small side note is that the 2 and the 28 in the sample have no correlation to the result, I just wanted a completely random result.