1.生成四位随机不重复验证码
//生成一个四位不重复的随机码 public static String get4Codes(){ StringBuffer sb = new StringBuffer(); String codes = "qwertyuiopasdfghjklzxcvbnm0123456789"; Random random = new Random(); for (int i =0; i< codes.length(); i++){ char c = codes.charAt(random.nextInt(codes.length())); if (sb.length() == 4) break; if (!sb.toString().contains(c+"")) sb.append(c); } return sb.toString(); }
时间: 2024-11-07 15:52:29