随机生成验证码
来源:互联网 发布:网络销售保健品诈骗案 编辑:程序博客网 时间:2024/06/06 11:41
private static int r; private static int g; private static int b;private static StringBuffer buffer; public static final char[] CHARS = { '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; public static Random random = new Random(); // 获取8位随机数 public static String getRandomString() { // 缓存字符串 buffer = new StringBuffer(); for (int i = 0; i < 6; i++) { // 每次取一个随机字符 buffer.append(CHARS[random.nextInt(CHARS.length)]); } return buffer.toString(); } public static void color(){ getRandomString(); r=(int) (Math.random()*255); g=(int) (Math.random()*255); b=(int) (Math.random()*255); denglu_textview1.setText(getRandomString()); denglu_textview1.setTextColor(Color.rgb(r, g, b)); denglu_textview1.setBackgroundColor(Color.rgb(255-r,255-g, 255-b)); }
Xml布局,使用TextView
从26个字母和10个数字中随机取出6个字符, ,除去"l","1""0"0'等相似的字符,
颜色使用rgb
setText(Color.rgb(r,g,b);
利用Math.random()*255随机生成r,g,b范围是0-255
背景使用反色:255-r,255-g,255-b,防止背景跟字体分不清
0 0
- 生成随机验证码
- 随机生成验证码
- 生成随机验证码
- 随机生成验证码
- 生成随机验证码
- 生成随机验证码
- 生成随机验证码
- 生成随机验证码
- 随机生成验证码
- 随机生成验证码
- 随机生成验证码
- 随机生成验证码
- 随机生成验证码
- 生成随机验证码
- 随机生成验证码
- 随机生成验证码
- 生成随机验证码
- 生成随机验证码
- 64位windows8.1编译openjdk8
- swift 命名空间
- android intent和intent action大全
- MySQL中文编码GBK,utf-8
- Emacs 编辑环境,第 1 部分.
- 随机生成验证码
- 剑指offer - 实现Singleton模式
- 2566:硬币统计
- 插入排序
- Emacs 编辑环境,第 2 部分: 学习 Emacs 的基本模式和编辑特性
- Emacs 编辑环境,第 3 部分: 高级 Emacs 文本操作
- Lua和Luajit的优势和不足(1)
- linux安装mysql步骤(unrecognized service错误)
- Emacs 编辑环境,第 4 部分: 选项、寄存器和书签