| | |
| | | import java.util.Collection; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Random; |
| | | |
| | | /** |
| | | * 字符串工具类 |
| | |
| | | */ |
| | | private static final char ASTERISK = '*'; |
| | | |
| | | public static String getCharAndNum(int length) { |
| | | StringBuilder val = new StringBuilder(); |
| | | Random random = new Random(); |
| | | for (int i = 0; i < length; i++) { |
| | | // 输出字母还是数字 |
| | | String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; |
| | | // 字符串 |
| | | if ("char".equalsIgnoreCase(charOrNum)) { |
| | | // 取得大写字母还是小写字母 |
| | | int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; |
| | | val.append((char) (choice + random.nextInt(26))); |
| | | // 数字 |
| | | } else if ("num".equalsIgnoreCase(charOrNum)) { |
| | | val.append(random.nextInt(10)); |
| | | } |
| | | } |
| | | return val.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 获取参数不为空值 |
| | | * |