Package com.biglybt.core.util
Class RandomUtils
java.lang.Object
com.biglybt.core.util.RandomUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final int
static final int
static final Random
static final SecureRandom
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
generateRandomAlphanumerics
(int num_to_generate) Generate a random string of characters.static byte[]
generateRandomBytes
(int num_to_generate) Generate a random array of bytes.static int
generateRandomIntBetween
(int min, int max) static int
generateRandomIntUpto
(int max) static int
Generate a random port number for binding a network IP listening socket to.static int
generateRandomNetworkListenPort
(int min_port, int max_port) static int
Generates a random +1 or -1static int
static long
static byte
nextByte()
static void
nextBytes
(byte[] bytes) static float
static byte[]
nextHash()
static int
nextInt()
static int
nextInt
(int n) static long
nextLong()
static long
nextLong
(long n) static long
static void
nextSecureBytes
(byte[] bytes) static byte[]
-
Field Details
-
RANDOM
-
INSTANCE_ID
-
SECURE_RANDOM
-
LISTEN_PORT_MIN
public static final int LISTEN_PORT_MIN- See Also:
-
LISTEN_PORT_MAX
public static final int LISTEN_PORT_MAX- See Also:
-
-
Constructor Details
-
RandomUtils
public RandomUtils()
-
-
Method Details
-
generateRandomBytes
public static byte[] generateRandomBytes(int num_to_generate) Generate a random array of bytes.- Parameters:
num_to_generate
- number of bytes to generate- Returns:
- random byte array
-
generateRandomAlphanumerics
Generate a random string of characters.- Parameters:
num_to_generate
- number of chars to generate- Returns:
- random char string
-
generateRandomNetworkListenPort
public static int generateRandomNetworkListenPort()Generate a random port number for binding a network IP listening socket to. NOTE: Will return a valid non-privileged port number >= LISTEN_PORT_MIN and invalid input: '<'= LISTEN_PORT_MAX.- Returns:
- random port number
-
generateRandomNetworkListenPort
public static int generateRandomNetworkListenPort(int min_port, int max_port) -
generateRandomPlusMinus1
public static int generateRandomPlusMinus1()Generates a random +1 or -1- Returns:
- +1 or -1
-
nextFloat
public static float nextFloat() -
nextBytes
public static void nextBytes(byte[] bytes) -
nextSecureBytes
public static void nextSecureBytes(byte[] bytes) -
nextSecureHash
public static byte[] nextSecureHash() -
nextHash
public static byte[] nextHash() -
nextInt
public static int nextInt(int n) -
nextByte
public static byte nextByte() -
nextInt
public static int nextInt() -
nextAbsoluteInt
public static int nextAbsoluteInt() -
nextLong
public static long nextLong() -
nextLong
public static long nextLong(long n) -
nextAbsoluteLong
public static long nextAbsoluteLong() -
nextSecureAbsoluteLong
public static long nextSecureAbsoluteLong() -
generateRandomIntUpto
public static int generateRandomIntUpto(int max) - Returns:
- random int between 0 and max-1. e.g. param of 10 returns 0->9
-
generateRandomIntBetween
public static int generateRandomIntBetween(int min, int max) - Returns:
- random int between min and max, e.g params of [5,7] returns 5,6 or 7
-