Commit 6e411ccf by zhengxj

finish 随机码工具类 on 20190118 by zhengxj

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@16778 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 0778e3d9
/**
*
*/
package com.glsx.manager.utils;
/**
* @ClassName: NumberUtils
* @Description: TODO(这里用一句话描述这个类的作用)
* @author Zheng Xiajun
* @date 2019年1月18日
*
*/
public class CodeUtils {
/**
*
* @author Zheng Xiajun
* @Title: generateUniqueRandomCode
* @Description: 生成字母数字混合随机码
* @param digit 需要的随机码位数
* @return String 返回类型
*
*/
public static String generateUniqueRandomCode(int digit) {
String randomcode = "";
// 用字符数组的方式随机
String model = "0123456789abcdefghijklmnopqrstuvwxyz";
char[] m = model.toCharArray();
for (int j = 0; j < digit; j++) {
char c = m[(int) (Math.random() * 36)];
// 保证六位随机数之间没有重复的
if (randomcode.contains(String.valueOf(c))) {
j--;
continue;
}
randomcode = randomcode + c;
}
return randomcode;
}
public static void main(String args[]){
System.out.println(generateUniqueRandomCode(4));
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!