package com.diagbot.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @Description: 短信验证码生成工具类
 * @author: gaodm
 * @time: 2018/9/3 15:21
 */
public final class SmsCodeUtil {

    private static final String AUTH_CODE = "0123456789";

    public static String getVerCode(){
        return getVerCode(6);
    }
    public static String getVerCode(Integer size)
    {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < size; i++)
        {
            int index = new Random().nextInt(AUTH_CODE.length());
            sb.append(AUTH_CODE.charAt(index));
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        List<String> test = new ArrayList<>();
        //int i = 0;
        while(true){
            String result = getVerCode();
            if(test.contains(result)){
                System.out.println("出现了重复编码:" + result);
                break;
            }
            test.add(result);
            //System.out.println(i++);
            System.out.println(result);
        }
    }
}
