Class RandomUtils


  • public class RandomUtils
    extends java.lang.Object
    Collection of small static helper routines for logged pseudo-random number generation.
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> T getRandomMember​(java.util.logging.Logger logger, java.lang.String logMe, java.util.List<T> list, java.util.Random random)
      Gets a random member of a list.
      static <T> T getRandomMember​(java.util.logging.Logger logger, java.lang.String logMe, java.util.stream.Stream<T> stream, java.util.Random random)
      Gets a random member of a stream.
      static void logArray​(java.util.logging.Logger logger, java.lang.String logMe, int[] arr)
      Log an array of ints at Level.FINEST.
      static double randomDouble​(java.util.logging.Logger logger, java.lang.String logMe, java.util.Random random)
      Convenience to aid logging uses of Randoms.
      static float randomFloat​(java.util.logging.Logger logger, java.lang.String logMe, java.util.Random random)
      Convenience to aid logging uses of Randoms.
      static int randomInt​(java.util.logging.Logger logger, java.lang.String logMe, java.util.Random random, int range)
      Convenience to aid logging uses of Randoms.
      static int[] randomInts​(java.util.logging.Logger logger, java.lang.String logMe, java.util.Random random, int range, int n)
      Convenience to aid logging uses of Randoms.
      static void randomShuffle​(java.util.logging.Logger logger, java.lang.String logMe, java.util.List<?> list, java.util.Random random)
      Shuffle a list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RandomUtils

        public RandomUtils()
    • Method Detail

      • randomInt

        public static int randomInt​(java.util.logging.Logger logger,
                                    java.lang.String logMe,
                                    java.util.Random random,
                                    int range)
        Convenience to aid logging uses of Randoms.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        random - A pseudo-Random number source.
        range - The exclusive maximum integer to return.
        Returns:
        A pseudo-random integer r, 0 ≤ r < range.
      • logArray

        public static void logArray​(java.util.logging.Logger logger,
                                    java.lang.String logMe,
                                    int[] arr)
        Log an array of ints at Level.FINEST.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        arr - The array of ints to log.
      • randomInts

        public static int[] randomInts​(java.util.logging.Logger logger,
                                       java.lang.String logMe,
                                       java.util.Random random,
                                       int range,
                                       int n)
        Convenience to aid logging uses of Randoms.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        random - A pseudo-Random number source.
        range - The exclusive maximum integer to return.
        n - The number of randoms.
        Returns:
        A vector of pseudo-random integers r, 0 ≤ r < range.
      • randomFloat

        public static float randomFloat​(java.util.logging.Logger logger,
                                        java.lang.String logMe,
                                        java.util.Random random)
        Convenience to aid logging uses of Randoms.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        random - A pseudo-Random number source.
        Returns:
        A pseudo-random double r, 0 ≤ r < 1.0.
      • randomDouble

        public static double randomDouble​(java.util.logging.Logger logger,
                                          java.lang.String logMe,
                                          java.util.Random random)
        Convenience to aid logging uses of Randoms.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        random - A pseudo-Random number source.
        Returns:
        A pseudo-random double r, 0 ≤ r < 1.0.
      • getRandomMember

        public static <T> T getRandomMember​(java.util.logging.Logger logger,
                                            java.lang.String logMe,
                                            java.util.List<T> list,
                                            java.util.Random random)
        Gets a random member of a list.
        Type Parameters:
        T - The list member type.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        list - The list.
        random - A random number source.
        Returns:
        A random member from the list.
      • getRandomMember

        public static <T> T getRandomMember​(java.util.logging.Logger logger,
                                            java.lang.String logMe,
                                            java.util.stream.Stream<T> stream,
                                            java.util.Random random)
        Gets a random member of a stream.
        Type Parameters:
        T - The list member type.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        stream - The Stream to pick from.
        random - A random number source.
        Returns:
        A random member from the stream.
      • randomShuffle

        public static void randomShuffle​(java.util.logging.Logger logger,
                                         java.lang.String logMe,
                                         java.util.List<?> list,
                                         java.util.Random random)
        Shuffle a list.
        Parameters:
        logger - The Logger to log to.
        logMe - A string to log with the result.
        list - The list.
        random - A random number source.