code: public static String generateString(int length) {
          char[] buf = new char[length];
          for (int i = 0; i < buf.length; i++) {
              buf[i] = chars.charAt(random.nextInt(chars.length()));
          }
          return new String(buf);
      }
docs: Creates a random string using only lowercase ascii letters, uppercase
  ascii letters, and digits.  This method internally uses a static instance
  of a Random() object.
  @param length The length of random string to generate
  @return A new random string with a length specified in the length parameter