RandomUtil.java 776 Bytes
package com.subsidy.util;

import cn.hutool.core.lang.UUID;

import java.util.Random;

public class RandomUtil {

    public static int getCode() {
        return (int)((Math.random() * 9 + 1) * 100000);
    }

    public static String getRandomCode(int randomLength) {
        StringBuilder str = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < randomLength; i++) {
            str.append(random.nextInt(10));
        }
        return str.toString();
    }


    /**
     * 随机生成订单号
     */
    public static String  randomOrderNumber(){
        return UUID.fastUUID().toString().replace("-","").substring(0,29);
    }

    public static void main(String[] args) {
        System.out.println(randomOrderNumber());
    }

}