public static String getRundom(){ // 48-57 65-90 97-122 StringBuffer id=new StringBuffer(); Random random = new Random(); for (int i = 0; i < 8; i++) { char s = 0; int j=random.nextInt(3) % 4; switch (j) { case 0: //随机生成数字 s = (char) (random.nextInt(57) % (57 - 48 + 1) + 48); break; case 1: //随机生成大写字母 s = (char) (random.nextInt(90) % (90 - 65 + 1) + 65); break; case 2: //随机生成小写字母 s = (char) (random.nextInt(122) % (122 - 97 + 1) + 97); break; } id.append(s); } return id.toString(); }