package com.codvision.commoncore.utils;

import java.util.Random;

/**
 * @author: fuyuaaaaa
 * @description: 随机数 工具 类
 * @program: smart-rear
 * @creat: 2018-09-21 10:10
 **/
public class RandomUtil {

    /**
     * 获取6位数验证码
     *
     * @return 验证码
     */
    public static String getVerificationCode() {
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 6; i++) {
            int a = random.nextInt(10);
            sb.append(a);
        }
        return sb.toString();
    }

    /**
     * 获取指定长度验证码
     *
     * @param length 长度
     * @return 验证码
     */
    public static String getRandomStr(int length) {
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random random = new Random();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(26);
            stringBuilder.append(str.charAt(number));
        }
        return stringBuilder.toString();
    }

}
