Class RandomUtils
java.lang.Object
com.biglybt.core.util.RandomUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final intstatic final intstatic final Randomstatic final SecureRandom -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateRandomAlphanumerics(int num_to_generate) Generate a random string of characters.static byte[]generateRandomBytes(int num_to_generate) Generate a random array of bytes.static intgenerateRandomIntBetween(int min, int max) static intgenerateRandomIntUpto(int max) static intGenerate a random port number for binding a network IP listening socket to.static intgenerateRandomNetworkListenPort(int min_port, int max_port) static intGenerates a random +1 or -1static intstatic longstatic bytenextByte()static voidnextBytes(byte[] bytes) static floatstatic byte[]nextHash()static intnextInt()static intnextInt(int n) static longnextLong()static longnextLong(long n) static longstatic voidnextSecureBytes(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
-