这个是我从之前项目中看到了,觉得不错,记录一下(个人感觉简单又实用)
简单的说就是随机一个数转换成char类型,用的是ASC||编码表
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17public static String getRandomCode(int number) { String codeNum = ""; int[] code = new int[3]; Random random = new Random(); for (int i = 0; i < number; i++) { int num = random.nextInt(10) + 48; int uppercase = random.nextInt(26) + 65; int lowercase = random.nextInt(26) + 97; code[0] = num; code[1] = uppercase; code[2] = lowercase; codeNum += (char) code[random.nextInt(3)]; //codeNum += (char) code[random.nextInt(2)]; } return codeNum; }
最后
以上就是机灵草丛最近收集整理的关于生成一个随机数字+字母的字符串的全部内容,更多相关生成一个随机数字+字母内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复