zoukankan      html  css  js  c++  java
  • 生成规则:Q+年后两位+月+日卡券类型+八位字母和数字随机

    public class xxxGenerator {

    private char[] arr = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','L','M','N',
    'P','Q','R','S','T','U','V','W','X','Y','Z'};
    private Integer bitCount = 8;
    /**
    * @desc : 生成规则:Q+年后两位+月+日卡券类型+八位字母和数字随机
    **/
    public String generator(xxTypeEnum type){
    LocalDateTime nowTime = LocalDateTime.now();
    StringBuffer sb = new StringBuffer();
    sb.append("Q");
    sb.append(String.valueOf(nowTime.getYear()).substring(2,4));
    sb.append(String.format("%02d",nowTime.getMonthValue()));
    sb.append(String.format("%02d",nowTime.getDayOfMonth()));
    sb.append(type.getValue());
    Random random = new Random();
    for(int i=0;i<bitCount;i++){
    sb.append(arr[random.nextInt(arr.length)]);
    }
    log.info("生成xx:{}",sb.toString());
    return sb.toString();
    }

    public Set<String> next(TypeEnum type, int quantity){
    Set<String> codes = Sets.newHashSet();
    for (;codes.size() < quantity;){
    // String uuid = UUID.randomUUID().toString().replace("-", "");
    String code = generator(type);
    codes.add(code);
    }

    return codes;
    }
    }
  • 相关阅读:
    Algs4-2.2.24-改进的有序测试
    Algs4-2.2.23-2比较正文中实现的归并和反向复制辅助数组归并之间的性能
    ssh登录卡住问题
    DELL R730安装ESXI虚拟化
    Linux umount的device is busy问题
    shell脚本调试技巧
    git编译安装
    卸载gitlab
    磁盘性能测试方法
    N! HDU 1042
  • 原文地址:https://www.cnblogs.com/maohuidong/p/14005865.html
Copyright © 2011-2022 走看看