实现原理,通过随机生成1-52的随机数,然后从定义好的字母数字中取元素进行组合。
下面是代码:
public static void login(){String [] yan ={"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",};int a = (int)(Math.random()*52);int b = (int)(Math.random()*52);int c = (int)(Math.random()*52);int d = (int)(Math.random()*52);String yanzhengma = yan[a]+yan[b]+yan[c]+yan[d];System.out.println(yanzhengma);}
也可以自行扩展实现数字加字母组合的验证码。
欢迎关注哦: