| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package com.fdkankan.common.util;
- import java.util.*;
- public class RandomUtil {
- public static String[] chars = new String[] { "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", "0", "1", "2", "3", "4", "5",
- "6", "7", "8", "9", "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" };
- public static String generateShortUuid() {
- StringBuffer shortBuffer = new StringBuffer();
- String uuid = UUID.randomUUID().toString().replace("-", "");
- int index = 0;
- for (int i = 0; i < 9; i++) {
- index = i;
- if(index >= 8){
- index = i % 8;
- uuid = UUID.randomUUID().toString().replace("-", "");
- }
- String str = uuid.substring(index * 4, index * 4 + 4);
- int x = Integer.parseInt(str, 16);
- shortBuffer.append(chars[x % 0x3E]);
- }
- return shortBuffer.toString();
- }
- /**
- * 获取随机字符串
- *
- * @param num
- * @return
- */
- public static String getRandomNum(Integer num) {
- String base = "0123456789ABCDEF";
- Random random = new Random();
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < num; i++) {
- int number = random.nextInt(base.length());
- sb.append(base.charAt(number));
- }
- return sb.toString();
- }
- public static void main(String[] args) {
- // Set<String> set = new HashSet<>();
- //
- // while(true){
- // if(set.size() == 650){
- // break;
- // }
- // set.add("4DKKPRO_07" + getRandomNum(7));
- //// set.add("4DKKLITE_11" + getRandomNum(7));
- // }
- //
- // for(String s : set){
- // System.out.println(s);
- // }
- // String[] nums = num.split(",");
- //
- // List arrayList = new ArrayList();
- // for(String a:nums){
- // arrayList.add(a);
- // }
- //
- // for(int i = 0;i<100;i++ ){
- // String numss = "07"+getRandomNum(7);
- // if(!arrayList.contains(numss)){
- // System.out.println("07"+getRandomNum(7));
- // }
- //
- // }
- // System.out.println(generateShortUuid());
- }
- }
|