Class BiasedNumbers

java.lang.Object
com.carrotsearch.randomizedtesting.generators.BiasedNumbers

public final class BiasedNumbers extends 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).
  • Field Details

  • Constructor Details

    • BiasedNumbers

      public BiasedNumbers()
  • Method Details

    • randomDoubleBetween

      public static double randomDoubleBetween(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(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(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(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(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(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)