Class BiasedNumbers


  • public final class BiasedNumbers
    extends java.lang.Object
    Utility classes for selecting numbers at random, but not necessarily in an uniform way. The implementation will try to pick "evil" numbers more often than uniform selection would. This includes exact range boundaries, numbers very close to range boundaries, numbers very close (or equal) to zero, etc. The exact method of selection is implementation-dependent and may change (if we find even more evil ways).
    • Constructor Summary

      Constructors 
      Constructor Description
      BiasedNumbers()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static int flip​(int floatBits)  
      private static long flip​(long bits)  
      private static float fromSortable​(int sortable)  
      private static double fromSortable​(long sortable)  
      static double fuzzDown​(java.util.Random r, double v, double min)
      Fuzzify the input value by decreasing it by a few ulps, but never past min.
      static float fuzzDown​(java.util.Random r, float v, float min)
      Fuzzify the input value by decreasing it by a few ulps, but never past min.
      static double fuzzUp​(java.util.Random r, double v, double max)
      Fuzzify the input value by increasing it by a few ulps, but never past max.
      static float fuzzUp​(java.util.Random r, float v, float max)
      Fuzzify the input value by increasing it by a few ulps, but never past max.
      static double randomDoubleBetween​(java.util.Random r, double min, double max)
      A random double between min (inclusive) and max (inclusive).
      static float randomFloatBetween​(java.util.Random r, float min, float max)
      A random float between min (inclusive) and max (inclusive).
      private static long toSortable​(double value)  
      private static int toSortable​(float value)  
      • Methods inherited from class java.lang.Object

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

      • BiasedNumbers

        public BiasedNumbers()
    • Method Detail

      • randomDoubleBetween

        public static double randomDoubleBetween​(java.util.Random r,
                                                 double min,
                                                 double max)
        A random double between min (inclusive) and max (inclusive). If you wish to have an exclusive range, use Math.nextAfter(double, double) to adjust the range. The code was inspired by GeoTestUtil from Apache Lucene.
        Parameters:
        min - Left range boundary, inclusive. May be Double.NEGATIVE_INFINITY, but not NaN.
        max - Right range boundary, inclusive. May be Double.POSITIVE_INFINITY, but not NaN.
      • fuzzDown

        public static double fuzzDown​(java.util.Random r,
                                      double v,
                                      double min)
        Fuzzify the input value by decreasing it by a few ulps, but never past min.
      • fuzzUp

        public static double fuzzUp​(java.util.Random r,
                                    double v,
                                    double max)
        Fuzzify the input value by increasing it by a few ulps, but never past max.
      • fromSortable

        private static double fromSortable​(long sortable)
      • toSortable

        private static long toSortable​(double value)
      • flip

        private static long flip​(long bits)
      • randomFloatBetween

        public static float randomFloatBetween​(java.util.Random r,
                                               float min,
                                               float max)
        A random float between min (inclusive) and max (inclusive). If you wish to have an exclusive range, use Math.nextAfter(float, double) to adjust the range. The code was inspired by GeoTestUtil from Apache Lucene.
        Parameters:
        min - Left range boundary, inclusive. May be Float.NEGATIVE_INFINITY, but not NaN.
        max - Right range boundary, inclusive. May be Float.POSITIVE_INFINITY, but not NaN.
      • fuzzDown

        public static float fuzzDown​(java.util.Random r,
                                     float v,
                                     float min)
        Fuzzify the input value by decreasing it by a few ulps, but never past min.
      • fuzzUp

        public static float fuzzUp​(java.util.Random r,
                                   float v,
                                   float max)
        Fuzzify the input value by increasing it by a few ulps, but never past max.
      • fromSortable

        private static float fromSortable​(int sortable)
      • toSortable

        private static int toSortable​(float value)
      • flip

        private static int flip​(int floatBits)