import java.security.SecureRandom; import java.util.Random; public class VerCodeGenerateUtil { private static final String SYMBOLS = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ"; private static final Random RANDOM = new SecureRandom(); /** * 生成4位随机验证码 * @return 返回4位验证码 */ public static String getVerCode() { char[] nonceChars = new char[4]; for (int index = 0; index < nonceChars.length; ++index) { nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length())); } return new String(nonceChars); } }
Java 生成四位数验证码工具类
最新推荐文章于 2024-11-04 22:26:34 发布