Java生成随机字母6位数

          /**
              * java生成随机字母6位数
              * @param length[生成随机数的长度]
              * @return
              */
             public static String getRandomNickname(int length) {
              String val = "";
              Random random = new Random();
              for (int i = 0; i < length; i++) {
               // 字符串
                // 取得大写字母还是小写字母
                int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
                val += (char) (choice + random.nextInt(26));
              }
              return val;
             }
             public static void main(String[] args) {
                 System.out.println("java生成随机字母6位数:" + getRandomNickname(6));
            }

猜你喜欢

转载自blog.csdn.net/damoneric_guo/article/details/110803397
今日推荐