Class BiasedNumbers
- java.lang.Object
-
- com.carrotsearch.randomizedtesting.generators.BiasedNumbers
-
public final class BiasedNumbers extends java.lang.ObjectUtility 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 Summary
Fields Modifier and Type Field Description private static intEVIL_RANDOM_REPRESENTATION_BITSprivate static intEVIL_RANGE_LEFTprivate static intEVIL_RANGE_RIGHTprivate static intEVIL_SIMPLE_PROPORTIONprivate static intEVIL_VERY_CLOSE_RANGE_ENDSprivate static intEVIL_ZERO_OR_NEAR
-
Constructor Summary
Constructors Constructor Description BiasedNumbers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static intflip(int floatBits)private static longflip(long bits)private static floatfromSortable(int sortable)private static doublefromSortable(long sortable)static doublefuzzDown(java.util.Random r, double v, double min)Fuzzify the input value by decreasing it by a few ulps, but never past min.static floatfuzzDown(java.util.Random r, float v, float min)Fuzzify the input value by decreasing it by a few ulps, but never past min.static doublefuzzUp(java.util.Random r, double v, double max)Fuzzify the input value by increasing it by a few ulps, but never past max.static floatfuzzUp(java.util.Random r, float v, float max)Fuzzify the input value by increasing it by a few ulps, but never past max.static doublerandomDoubleBetween(java.util.Random r, double min, double max)A random double betweenmin(inclusive) andmax(inclusive).static floatrandomFloatBetween(java.util.Random r, float min, float max)A random float betweenmin(inclusive) andmax(inclusive).private static longtoSortable(double value)private static inttoSortable(float value)
-
-
-
Field Detail
-
EVIL_RANGE_LEFT
private static final int EVIL_RANGE_LEFT
- See Also:
- Constant Field Values
-
EVIL_RANGE_RIGHT
private static final int EVIL_RANGE_RIGHT
- See Also:
- Constant Field Values
-
EVIL_VERY_CLOSE_RANGE_ENDS
private static final int EVIL_VERY_CLOSE_RANGE_ENDS
- See Also:
- Constant Field Values
-
EVIL_ZERO_OR_NEAR
private static final int EVIL_ZERO_OR_NEAR
- See Also:
- Constant Field Values
-
EVIL_SIMPLE_PROPORTION
private static final int EVIL_SIMPLE_PROPORTION
- See Also:
- Constant Field Values
-
EVIL_RANDOM_REPRESENTATION_BITS
private static final int EVIL_RANDOM_REPRESENTATION_BITS
- See Also:
- Constant Field Values
-
-
Method Detail
-
randomDoubleBetween
public static double randomDoubleBetween(java.util.Random r, double min, double max)A random double betweenmin(inclusive) andmax(inclusive). If you wish to have an exclusive range, useMath.nextAfter(double, double)to adjust the range. The code was inspired by GeoTestUtil from Apache Lucene.- Parameters:
min- Left range boundary, inclusive. May beDouble.NEGATIVE_INFINITY, but not NaN.max- Right range boundary, inclusive. May beDouble.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 betweenmin(inclusive) andmax(inclusive). If you wish to have an exclusive range, useMath.nextAfter(float, double)to adjust the range. The code was inspired by GeoTestUtil from Apache Lucene.- Parameters:
min- Left range boundary, inclusive. May beFloat.NEGATIVE_INFINITY, but not NaN.max- Right range boundary, inclusive. May beFloat.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)
-
-