public String generateCode(int length, int maxInt){
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < length; ++ i) {
      sb.append(random.nextInt(maxInt+1));
    }
    return sb.toString();
  }