Blame view

RandomUtil.java 776 Bytes
涂亚平 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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());
    }

}