package com.example.xiaoshiweixinback.business.utils; import java.util.Random; public class RandomUtil { /** * 随机验证码 * @return */ public static String getSixRandom(){ return String.valueOf((int) ((Math.random() * 9 + 1) * Math.pow(10, 5))); } private static String[] STR_ARR = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; public static String generateRandomString(int length) { StringBuilder sb = new StringBuilder(); Random rand = new Random(); for (int i = 0; i < length; i++) { sb.append(STR_ARR[rand.nextInt(STR_ARR.length)]); } return sb.toString(); } }