package com.lovenav.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;
import java.util.UUID;

//随机数
public class RandomUtils {
    //生成激活码
    public static String createActive() {
        // 生成4位随机数字+字母,
            String val = "";
            Random random = new Random();
            // 参数length，表示生成几位随机数
            for (int i = 0; i < 4; i++) {
                String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
                // 输出字母还是数字
                if ("char".equalsIgnoreCase(charOrNum)) {
                    // 输出是大写字母还是小写字母
                    int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;
                    val += (char) (random.nextInt(26) + temp);
                } else if ("num".equalsIgnoreCase(charOrNum)) {
                    val += String.valueOf(random.nextInt(10));
                }
            }
        return  val;


    }

    //设置时间戳
    public static String getTime() {
        return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(Calendar.getInstance().getTime());
    }

    //生成订单编号
    public static String createOrderId() {
        return getTime() + UUID.randomUUID().toString();
    }
}
