package com.yeejoin.precontrol.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @description: 全局生成唯一ID
 * @author: king
 * @create: 2019-05-28 13:57
 **/
public class RandomUtils {
    public static Long get() {
        SimpleDateFormat sdf = new SimpleDateFormat("ddHHmmss");
        String newDate = sdf.format(new Date());
        String result = "";
        Random random = new Random();
        for (int i = 0; i < 3; i++) {
            result += random.nextInt(10);
        }
        return Long.valueOf(newDate + result);
    }

    /**
     * 根据指定长度生成随机下标
     *
     * @param size
     * @return
     */
    public static Integer getRandomIndex(Integer size) {
        ThreadLocalRandom random = ThreadLocalRandom.current();
        int MAX = size;
        int MIN = 0;
        return random.nextInt(MAX - MIN + 1) + MIN;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(getRandomIndex(100));
        }
    }
}