Class RandomUtils


  • public class RandomUtils
    extends java.lang.Object
    • Field Detail

      • RANDOM

        public static final java.util.Random RANDOM
      • INSTANCE_ID

        public static final java.lang.String INSTANCE_ID
      • SECURE_RANDOM

        public static final java.security.SecureRandom SECURE_RANDOM
    • Constructor Detail

      • RandomUtils

        public RandomUtils()
    • Method Detail

      • 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

        public static java.lang.String generateRandomAlphanumerics​(int num_to_generate)
        Generate a random string of charactors.
        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 <= 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