public class RandomUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.util.concurrent.ThreadLocalRandom |
MAIN_THREAD_RANDOM |
static java.util.Random |
RANDOM |
static java.security.SecureRandom |
SECURE_RANDOM |
| Constructor and Description |
|---|
RandomUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
randomBoolean() |
static byte |
randomByte(byte min,
byte max) |
static byte[] |
randomBytes(int length) |
static byte[] |
randomBytes(int minLength,
int maxLength) |
static char |
randomChar(char min,
char max) |
static double |
randomDouble(double min,
double max) |
static <T> T |
randomElement(java.util.List<T> list) |
static <T> T |
randomElement(T[] array) |
static float |
randomFloat(float min,
float max) |
static int |
randomInt(int min,
int max) |
static long |
randomLong(long min,
long max) |
static short |
randomShort(short min,
short max) |
static java.lang.String |
randomString(int length,
boolean lowercase,
boolean uppercase,
boolean number,
boolean special)
Generates a random string with the specified length and characters.
|
static java.lang.String |
randomString(int minLength,
int maxLength,
boolean lowercase,
boolean uppercase,
boolean number,
boolean special)
Generates a random string with the specified length and characters.
|
public static final java.util.Random RANDOM
public static final java.security.SecureRandom SECURE_RANDOM
public static final java.util.concurrent.ThreadLocalRandom MAIN_THREAD_RANDOM
public static int randomInt(int min,
int max)
min - The minimum value.max - The maximum value.public static double randomDouble(double min,
double max)
min - The minimum value.max - The maximum value.public static float randomFloat(float min,
float max)
min - The minimum value.max - The maximum value.public static long randomLong(long min,
long max)
min - The minimum value.max - The maximum value.public static short randomShort(short min,
short max)
min - The minimum value.max - The maximum value.public static byte randomByte(byte min,
byte max)
min - The minimum value.max - The maximum value.public static char randomChar(char min,
char max)
min - The minimum value.max - The maximum value.public static boolean randomBoolean()
public static <T> T randomElement(T[] array)
T - The type of the array.array - The array to get the random element from.public static <T> T randomElement(java.util.List<T> list)
T - The type of the list.list - The list to get the random element from.public static byte[] randomBytes(int length)
length - The length of the byte array.public static byte[] randomBytes(int minLength,
int maxLength)
minLength - The minimum length of the byte array.maxLength - The maximum length of the byte array.public static java.lang.String randomString(int minLength,
int maxLength,
boolean lowercase,
boolean uppercase,
boolean number,
boolean special)
minLength - The minimum length of the string.maxLength - The maximum length of the string.lowercase - Whether to include lowercase characters.uppercase - Whether to include uppercase characters.number - Whether to include number characters.special - Whether to include special characters.public static java.lang.String randomString(int length,
boolean lowercase,
boolean uppercase,
boolean number,
boolean special)
length - The length of the string.lowercase - Whether to include lowercase characters.uppercase - Whether to include uppercase characters.number - Whether to include number characters.special - Whether to include special characters.