Class BiasedNumbers
- java.lang.Object
-
- com.carrotsearch.randomizedtesting.generators.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).
-
-
Field Summary
Fields Modifier and Type Field Description private static int
EVIL_RANDOM_REPRESENTATION_BITS
private static int
EVIL_RANGE_LEFT
private static int
EVIL_RANGE_RIGHT
private static int
EVIL_SIMPLE_PROPORTION
private static int
EVIL_VERY_CLOSE_RANGE_ENDS
private static int
EVIL_ZERO_OR_NEAR
-
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 betweenmin
(inclusive) andmax
(inclusive).static float
randomFloatBetween(java.util.Random r, float min, float max)
A random float betweenmin
(inclusive) andmax
(inclusive).private static long
toSortable(double value)
private static int
toSortable(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)
-
-