package org.jeecg.modules.utils;

import java.security.SecureRandom;
import java.util.Date;
import java.util.Random;

public class RandomStrUtil {
    private static final String SYMBOLS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // 数字和26个字母组成
    private static final Random RANDOM = new SecureRandom();

    /**
     * 获取长度为 6 的随机字母+数字
     * @return 随机数字
     */
    public static String getRandomNumber(Integer len) {
        char[] nonceChars = new char[len];  //指定长度为6位/自己可以要求设置
        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
        }
        return new String(nonceChars)+new Date().getTime();
    }

    public static String getRandomNumberCrossBar(Integer len) {
        char[] nonceChars = new char[len];  //指定长度为6位/自己可以要求设置
        for (int index = 0; index < nonceChars.length; ++index) {
            nonceChars[index] = SYMBOLS.charAt(RANDOM.nextInt(SYMBOLS.length()));
            if(index != 0){
                if(index % 5 == 0){
                    nonceChars[index] =  '-';
                }
            }
        }
        return new String(nonceChars)+"-"+new Date().getTime();
    }
}
