1 Star 0 Fork 0

iCopper/Utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MixNumberCharacterUtils.java 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
iCopper 提交于 2018-09-26 20:15 +08:00 . 项目中工具类
package com.leyou.common.Utils;
import com.sun.corba.se.impl.orbutil.ObjectStreamClassUtil_1_3;
import org.junit.Test;
import java.util.Random;
/*
* @author iCopper
* @ 2018/9/23 --21:37
*/
public class MixNumberCharacterUtils {
public static final String ALLCHAR = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String LETTERCHAR = "abcdefghijkllmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static final String NUMBERCHAR = "0123456789";
/**
* 返回一个定长的随机字符串(只包含大小写字母、数字)
*
* @param length
* 随机字符串长度
* @return 随机字符串
*/
public static String generateString(int length) {
StringBuffer sb = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
sb.append(ALLCHAR.charAt(random.nextInt(ALLCHAR.length())));
}
return sb.toString();
}
@Test
public void testDemo() {
String code = this.generateString(6);
System.out.println(code);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iCopper/Utils.git
git@gitee.com:iCopper/Utils.git
iCopper
Utils
Utils
master

搜索帮助