package com.bootdo.util;

import java.util.Random;

public class RandomUtils {
    /**
          * 获取从a至z，长度为length随机数
          *
          * @return
          */
        public static String getRandomStr(int length) {
            String base = "abcdefghijklmnopqrstuvwxyz";
           Random random = new Random();
           StringBuffer sb = new StringBuffer();
          for (int i = 0; i < length; i++) {
              int number = random.nextInt(base.length());
              sb.append(base.charAt(number));
          }
          return sb.toString();
       }

    /**
          * 获取随机长度随机字符
          *
          * @param length
          * @return
          */
    public static String getRandomString(int length) { // length表示生成字符串的长度
         String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
     for (int i = 0; i < length; i++) {
    int number = random.nextInt(base.length());
       sb.append(base.charAt(number));
    }
        return sb.toString();
    }

       /**
      * 获取随机长度随机数字
      *
      * @param length
      * @return
      */
    public static String getRandomNumString(int length) { // length表示生成字符串的长度
        String base = "0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(base.length());
            sb.append(base.charAt(number));
        }
        return sb.toString();
    }


}
