package com.live.utils;

import org.springframework.util.StringUtils;

import java.util.Random;

public class RandomStringUtil {
    /**
     *
     * @param string_length
     * @param randomstring
     * @return
     */
    public  static  String randomNumber(int string_length,String randomstring) {


        String chars = "1234567890";
        int randomstring_lenth;
        if(StringUtils.isEmpty(randomstring)|| null==randomstring)
            randomstring_lenth = 0;
        else
            randomstring_lenth = randomstring.length();

        if(randomstring.length()>=string_length)
            return  "error:前缀字符不得长于总字符长度";

        for (int i=0; i<string_length-randomstring_lenth; i++) {
            Random randomGenerator = new Random();
            int randomInt = randomGenerator.nextInt(chars.length());
            randomstring += chars.substring(randomInt,randomInt+1);

        }
        return randomstring;
    }

    public static  String randomMobile(String ...randomstring){
        String str="999";
        if(randomstring.length>0){
            str = randomstring[0];
        }
        return randomNumber(11,str);
    }

    public  static String random_name() {
        String names_first = "赵钱孙李周吴郑王杜贾谢林彭张陈何刘杨";
        String names_last="ABCDEFGHIJKLMNOPQRSTUVWXTZ";
        String names_num="零一二三四五六七八九十";
        String randomstring ="";

        Random randomGenerator = new Random();
        int randomInt = randomGenerator.nextInt(names_first.length());
        randomstring += names_first.substring(randomInt,randomInt+1);

        randomInt = randomGenerator.nextInt(names_last.length());
        randomstring += names_last.substring(randomInt,randomInt+1);

        randomInt = randomGenerator.nextInt(names_num.length());
        randomstring += names_num.substring(randomInt,randomInt+1);

        return randomstring;

    }
    public  static String randomString(int length) {

        String str ="";
        String chars="ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghijklmnopqrstuvwxyz0123456789";

        for (int i=0; i<length; i++) {
            Random randomGenerator = new Random();
            int randomInt = randomGenerator.nextInt(chars.length());
            str += chars.substring(randomInt,randomInt+1);

        }
        return str;

    }
}
