com.xiaoleilu.hutool
类 RandomUtil

java.lang.Object
  继承者 com.xiaoleilu.hutool.RandomUtil

public class RandomUtil
extends Object

随机工具类

作者:
xiaoleilu

构造方法摘要
RandomUtil()
           
 
方法摘要
static
<T> T
randomEle(List<T> list)
          随机获得列表中的元素
static
<T> T
randomEle(List<T> list, int limit)
          随机获得列表中的元素
static
<T> List<T>
randomEles(List<T> list, int count)
          随机获得列表中的一定量元素
static int randomInt()
          获得随机数
static int randomInt(int limit)
          获得指定范围内的随机数 [0,limit)
static int randomInt(int min, int max)
          获得指定范围内的随机数
static String randomNumbers(int length)
          获得一个只包含数字的字符串
static String randomString(int length)
          获得一个随机的字符串(只包含数字和字符)
static String randomString(String baseString, int length)
          获得一个随机的字符串
static String randomUUID()
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

RandomUtil

public RandomUtil()
方法详细信息

randomInt

public static int randomInt(int min,
                            int max)
获得指定范围内的随机数

参数:
min - 最小数
max - 最大数
返回:
随机数

randomInt

public static int randomInt()
获得随机数

返回:
随机数

randomInt

public static int randomInt(int limit)
获得指定范围内的随机数 [0,limit)

参数:
limit - 限制随机数的范围,不包括这个数
返回:
随机数

randomEle

public static <T> T randomEle(List<T> list)
随机获得列表中的元素

类型参数:
T - 元素类型
参数:
list - 列表
返回:
随机元素

randomEle

public static <T> T randomEle(List<T> list,
                              int limit)
随机获得列表中的元素

类型参数:
T - 元素类型
参数:
list - 列表
limit - 限制列表的前N项
返回:
随机元素

randomEles

public static <T> List<T> randomEles(List<T> list,
                                     int count)
随机获得列表中的一定量元素

类型参数:
T - 元素类型
参数:
list - 列表
count - 随机取出的个数
返回:
随机元素

randomString

public static String randomString(int length)
获得一个随机的字符串(只包含数字和字符)

参数:
length - 字符串的长度
返回:
随机字符串

randomNumbers

public static String randomNumbers(int length)
获得一个只包含数字的字符串

参数:
length - 字符串的长度
返回:
随机字符串

randomString

public static String randomString(String baseString,
                                  int length)
获得一个随机的字符串

参数:
baseString - 随机字符选取的样本
length - 字符串的长度
返回:
随机字符串

randomUUID

public static String randomUUID()
返回:
随机UUID


Copyright © 2014. All rights reserved.