Class RandomUtil

java.lang.Object
com.acanx.utils.incubator.RandomUtil

public class RandomUtil extends Object
RandomUtil
Since:
0.0.1.10
  • Method Details

    • getRandomStr

      public static String getRandomStr(int length)
      生成指定长度的随机字符串
      Parameters:
      length - String 字符串长度
      Returns:
      String 生成的字符串
    • random

      public static String random(int count, int start, int end, boolean letters, boolean numbers, char[] chars, Random random)
      来自 package org.apache.commons.lang3.RandomStringUtils;

      Creates a random string based on a variety of options, using supplied source of randomness.

      If start and end are both 0, start and end are set to ' ' and 'z', the ASCII printable characters, will be used, unless letters and numbers are both false, in which case, start and end are set to 0 and Character.MAX_CODE_POINT.

      If set is not null, characters between start and end are chosen.

      This method accepts a user-supplied Random instance to use as a source of randomness. By seeding a single Random instance with a fixed seed and using it for each call, the same random sequence of strings can be generated repeatedly and predictably.

      Parameters:
      count - 生成的目标字符串长度
      start - the position in set of chars to start at (inclusive)
      end - the position in set of chars to end before (exclusive)
      letters - only allow letters?
      numbers - 只允许数字?
      chars - the set of chars to choose randoms from, must not be empty. If null, then it will use the set of all chars.
      random - a source of randomness.
      Returns:
      the random string
      Throws:
      ArrayIndexOutOfBoundsException - if there are not (end - start) + 1 characters in the set array.
      IllegalArgumentException - if count < 0 or the provided chars array is empty.
      Since:
      2.0
    • getRandomNum

      @Alpha public static String getRandomNum(int length)
      生成随机数字符串
      Parameters:
      length - 长度
      Returns:
      随机数字符串