java生成验证码两种方法
来源:互联网 发布:网络作家收入怎么收税 编辑:程序博客网 时间:2024/05/22 03:36
/**
* 获取6位的随机数
*
* @return
*/
public static String getRandom6() {
StringBuffer str = new StringBuffer();
int[] intRet = new int[6];
int intRd = 0; // 存放随机数
int count = 0; // 记录生成的随机数个数
int flag = 0; // 是否已经生成过标志
while (count < 6) {
Random rdm = new Random(System.currentTimeMillis());
intRd = Math.abs(rdm.nextInt()) % 9 + 1;
for (int i = 0; i < count; i++) {
if (intRet[i] == intRd) {
flag = 1;
break;
} else {
flag = 0;
}
}
if (flag == 0) {
intRet[count] = intRd;
str.append(intRd);
count++;
}
}
return str.toString();
}
/**
* 生成num位的数字和字母组合
* @return
*/
public static String getRandom(int num) {
StringBuffer str = new StringBuffer();
int count = 0; // 记录生成的随机数个数
String[] strs = { "0", "1", "2", "3", "4", "5", "6", "7", "8","9",
"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s","d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m",
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N","M" };
while (count < num) {
int a=(int)(Math.random()*62);
str.append(strs[a]);
count ++;
}
return str.toString();
}
* 获取6位的随机数
*
* @return
*/
public static String getRandom6() {
StringBuffer str = new StringBuffer();
int[] intRet = new int[6];
int intRd = 0; // 存放随机数
int count = 0; // 记录生成的随机数个数
int flag = 0; // 是否已经生成过标志
while (count < 6) {
Random rdm = new Random(System.currentTimeMillis());
intRd = Math.abs(rdm.nextInt()) % 9 + 1;
for (int i = 0; i < count; i++) {
if (intRet[i] == intRd) {
flag = 1;
break;
} else {
flag = 0;
}
}
if (flag == 0) {
intRet[count] = intRd;
str.append(intRd);
count++;
}
}
return str.toString();
}
/**
* 生成num位的数字和字母组合
* @return
*/
public static String getRandom(int num) {
StringBuffer str = new StringBuffer();
int count = 0; // 记录生成的随机数个数
String[] strs = { "0", "1", "2", "3", "4", "5", "6", "7", "8","9",
"q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "a", "s","d", "f", "g", "h", "j", "k", "l", "z", "x", "c", "v", "b", "n", "m",
"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N","M" };
while (count < num) {
int a=(int)(Math.random()*62);
str.append(strs[a]);
count ++;
}
return str.toString();
}
阅读全文
1 0
- java生成验证码两种方法
- java生成登录验证码的方法
- 生成验证码方法--
- 验证码生成方法
- java web应用中验证码的生成方法.
- java生成验证码之方法(一)
- java生成验证码
- Java 生成验证码
- Java 验证码生成
- java 生成图片验证
- java生成验证码
- java生成验证码
- java生成验证码
- Java生成验证码
- Java生成验证码
- java生成验证码
- java生成验证码
- java验证码生成
- 资讯精选 | 浅析机器视觉测试系统市场现状
- 二叉树最大路径和
- python笔记----解构和封装
- 基于Innobackupex的增备及恢复
- CentOS 7 64位下MySQL5.7卸载改成MySQL5.6版本(YUM)
- java生成验证码两种方法
- UWP 手绘视频创作工具 “来画Pro” 技术分享系列
- HTML5新特性:FileReader 和 FormData
- 在Linux系统下,cat正常,vim打开乱码
- JavaSE (七)循环控制语句:while、do....while、for,break和continue用法
- 第一行代码第二版ListView的使用(listView复用遇到的坑)
- Android友盟统计分析集成
- python简单的购物车程序(含代码)
- 创建SpringMVC+Mybatis项目