博客
关于我
java中随机生成26个字母组合的随机验证码
阅读量:593 次
发布时间:2019-03-11

本文共 585 字,大约阅读时间需要 1 分钟。

实现原理,通过随机生成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);			}

也可以自行扩展实现数字加字母组合的验证码。

欢迎关注哦:

在这里插入图片描述

转载地址:http://ddktz.baihongyu.com/

你可能感兴趣的文章
Nacos配置中心集群原理及源码分析
查看>>
nacos配置自动刷新源码解析
查看>>
Nacos集群搭建
查看>>
nacos集群搭建
查看>>
nagios安装文档
查看>>
name_save matlab
查看>>
Nami 项目使用教程
查看>>
NAT-DDNS内网穿透技术,解决动态域名解析难题
查看>>
NativePHP:使用PHP构建跨平台桌面应用的新框架
查看>>
NAT技术
查看>>
NAT模式下虚拟机centOs和主机ping不通解决方法
查看>>
NAT的两种模式SNAT和DNAT,到底有啥区别?
查看>>
Navicat for MySQL 命令列 执行SQL语句 历史日志
查看>>
Navicat for MySQL 查看BLOB字段内容
查看>>
Navicat Premium 12 卸载和注册表的删除
查看>>
navicat 系列软件一点击菜单栏就闪退
查看>>
navicat 连接远程mysql
查看>>
Navicat下载和破解以及使用
查看>>
Navicat可视化界面导入SQL文件生成数据库表
查看>>
Neat Stuff to Do in List Controls Using Custom Draw
查看>>