Package org.drasyl.util
Class RandomUtil
- java.lang.Object
-
- org.drasyl.util.RandomUtil
-
public final class RandomUtil extends Object
Utility class for receiving pseudorandom values.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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 Detail
-
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
-
randomString
public static String randomString(int length)
Returns a string of the givenlength
containing pseudorandom alphanumeric characters.- Parameters:
length
- The length of the string- Returns:
- string containing pseudorandom alphanumeric characters
-
-