Class RandomNumbers


  • public final class RandomNumbers
    extends java.lang.Object
    Utility classes for selecting random numbers from within a range or the numeric domain for a given type.
    See Also:
    BiasedNumbers
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomNumbers()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static long nextLong​(java.util.Random rnd, long n)
      Similar to Random.nextInt(int), but returns a long between 0 (inclusive) and n (exclusive).
      static int randomIntBetween​(java.util.Random r, int min, int max)
      A random integer between min (inclusive) and max (inclusive).
      static long randomLongBetween​(java.util.Random r, long min, long max)
      A random long between min (inclusive) and max (inclusive).
      private static int toIntExact​(long value)  
      • Methods inherited from class java.lang.Object

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

      • RandomNumbers

        public RandomNumbers()
    • Method Detail

      • randomIntBetween

        public static int randomIntBetween​(java.util.Random r,
                                           int min,
                                           int max)
        A random integer between min (inclusive) and max (inclusive).
      • randomLongBetween

        public static long randomLongBetween​(java.util.Random r,
                                             long min,
                                             long max)
        A random long between min (inclusive) and max (inclusive).
      • nextLong

        public static long nextLong​(java.util.Random rnd,
                                    long n)
        Similar to Random.nextInt(int), but returns a long between 0 (inclusive) and n (exclusive).
        Parameters:
        rnd - Random generator.
        n - the bound on the random number to be returned. Must be positive.
        Returns:
        Returns a random number between 0 and n-1.
      • toIntExact

        private static int toIntExact​(long value)