package com.hx.util.code;
|
|
import com.hx.util.DateUtil;
|
import com.hx.util.StringUtils;
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import java.util.Date;
|
import java.util.Random;
|
|
/**生成编号工具
|
*/
|
public class NumberTool {
|
|
/**大小写字母*/
|
private static final String LETTER_ARR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
/**大小写字母和数字*/
|
private static final String LETTER_NUMBER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
/**小写字母*/
|
private static final String LETTER_SMALL = "abcdefghijklmnopqrstuvwxyz";
|
/**大写字母*/
|
private static final String LETTER_BIG = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
/**随机获大写字母组合
|
* @param lengrhCount 长度
|
* @return
|
*/
|
public static String letterBig(long lengrhCount){
|
char[] c = LETTER_BIG.toCharArray();
|
Random random = new Random();
|
|
StringBuilder data = new StringBuilder();
|
for( int i = 0; i < lengrhCount; i ++) {
|
data.append(c[random.nextInt(c.length)]);
|
}
|
return data.toString();
|
}
|
|
|
/**随机获小写字母组合
|
* @param lengrhCount 长度
|
* @return
|
*/
|
public static String letterSmall(long lengrhCount){
|
char[] c = LETTER_SMALL.toCharArray();
|
Random random = new Random();
|
|
StringBuilder data = new StringBuilder();
|
for( int i = 0; i < lengrhCount; i ++) {
|
data.append(c[random.nextInt(c.length)]);
|
}
|
return data.toString();
|
}
|
|
|
/**随机获取大小写字母和数字组合
|
* @param lengrhCount 长度
|
* @return
|
*/
|
public static String letterNumber(long lengrhCount){
|
char[] c = LETTER_NUMBER.toCharArray();
|
Random random = new Random();
|
|
StringBuilder data = new StringBuilder();
|
for( int i = 0; i < lengrhCount; i ++) {
|
data.append(c[random.nextInt(c.length)]);
|
}
|
return data.toString();
|
}
|
|
/**随机获取大小写字母组合
|
* @param lengrhCount 长度
|
* @return
|
*/
|
public static String letterRandom(long lengrhCount){
|
char[] c = LETTER_ARR.toCharArray();
|
Random random = new Random();
|
|
StringBuilder data = new StringBuilder();
|
for( int i = 0; i < lengrhCount; i ++) {
|
data.append(c[random.nextInt(c.length)]);
|
}
|
return data.toString();
|
}
|
|
/**随机生成字符串(0-9)
|
* @param lengthCount 长度
|
* @return
|
*/
|
public static String generateCardNo(long lengthCount) {
|
Random r=new Random();
|
//定义变长字符串
|
StringBuilder str = new StringBuilder();
|
for(int i=0;i<lengthCount;i++){
|
str.append(r.nextInt(10));
|
}
|
return str.toString();
|
}
|
|
|
}
|