代码如下:
两种方法都可用:
public class Random {public static String getCode(int length){String code = "";for(int i=0;i<length;i++){boolean boo = (int)(Math.random()*2)==0;if(boo){code += String.valueOf((int)(Math.random()*10));}else {int temp = (int)(Math.random()*2)==0?65:97;char ch = (char)(Math.random()*26+temp);code += String.valueOf(ch);}}return code;}public static String getVerify(int length){String code = "";String str = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASFGHJKLZXCVBNM";String[] strs = str.split("");for(int i = 0;i<length;i++){code += strs[(int)(Math.random()*strs.length)];}return code;} }
本文发布于:2024-02-01 06:45:06,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170674110634650.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |