Lots of use of StringBuilder above. I guess it's easy, but requires a function call per char, growing an array, etc... If using the stringbuilder, a suggestion is to specify the required capacity of the string ie.,
new StringBuilder(int capacity);
Here's a version that doesn't use a StringBuilder or String appending, and no dictionary.
public static String randomString(int length)
{
SecureRandom random = new SecureRandom();
char[] chars = new char[length];
for(int i=0;i<chars.length;i++)
{
int v = random.nextInt(10 + 26 + 26);
char c;
if (v < 10)
{
c = (char)('0' + v);
}
else if (v < 36)
{
c = (char)('a' - 10 + v);
}
else
{
c = (char)('A' - 36 + v);
}
chars[i] = c;
}
return new String(chars);
}