Package org.drasyl.util
Class RandomUtil
java.lang.Object
org.drasyl.util.RandomUtil
Utility class for receiving pseudorandom values.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte
Returns a single pseudorandom byte.static byte[]
randomBytes
(int count) Returns an array of lengthcount
containing pseudorandom bytes.static int
randomInt
(int max) Returns a pseudorandom, uniformly distributedint
value between 0 andmax
.static int
randomInt
(int min, int max) Returns a pseudorandom, uniformly distributedint
value betweenmin
andmax
.static long
randomLong
(long max) Returns a pseudorandom, uniformly distributedlong
value between 0 andmax
.static long
randomLong
(long min, long max) Returns a pseudorandom, uniformly distributedlong
value betweenmin
andmax
.static String
randomString
(int length) Returns a string of the givenlength
containing pseudorandom alphanumeric characters.
-
Method Details
-
randomInt
public static int randomInt(int min, int max) Returns a pseudorandom, uniformly distributedint
value betweenmin
andmax
.- Parameters:
min
- The lowest value to returnmax
- The highest value to return- Returns:
- Pseudorandom
int
- Throws:
IllegalArgumentException
- ifmin
is greater thenmax
-
randomInt
public static int randomInt(int max) Returns a pseudorandom, uniformly distributedint
value between 0 andmax
.- Parameters:
max
- The highest value to return- Returns:
- Pseudorandom
int
-
randomLong
public static long randomLong(long min, long max) Returns a pseudorandom, uniformly distributedlong
value betweenmin
andmax
.- Parameters:
min
- The lowest value to returnmax
- The highest value to return- Returns:
- Pseudorandom
long
- Throws:
IllegalArgumentException
- ifmin
is greater thenmax
-
randomLong
public static long randomLong(long max) Returns a pseudorandom, uniformly distributedlong
value between 0 andmax
.- Parameters:
max
- The highest value to return- Returns:
- Pseudorandom
long
-
randomBytes
public static byte[] randomBytes(int count) Returns an array of lengthcount
containing pseudorandom bytes.- Parameters:
count
- The length of the array- Returns:
- Array containing pseudorandom bytes
-
randomByte
public static byte randomByte()Returns a single pseudorandom byte.- Returns:
- a pseudorandom byte
-
randomString
Returns a string of the givenlength
containing pseudorandom alphanumeric characters.- Parameters:
length
- The length of the string- Returns:
- string containing pseudorandom alphanumeric characters
-