code: public String randomString(String permitted, int length) {
          StringBuilder result = new StringBuilder(length);
          int maxIndex = permitted.length();
          for (int i = 0; i < length; i++) {
              int index = random(maxIndex);
              char value = permitted.charAt(index);
              result.append(value);
          }
          return result.toString();
      }
docs: Creates a random string consisting only of supplied characters.
  @param permitted string consisting of permitted characters.
  @param length length of string to create.
  @return random string.