Class BiasedNumbers
java.lang.Object
com.carrotsearch.randomizedtesting.generators.BiasedNumbers
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
FieldsModifier and TypeFieldDescriptionprivate static final intprivate static final intprivate static final intprivate static final intprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static intflip(int floatBits) private static longflip(long bits) private static floatfromSortable(int sortable) private static doublefromSortable(long sortable) static doubleFuzzify the input value by decreasing it by a few ulps, but never past min.static floatFuzzify the input value by decreasing it by a few ulps, but never past min.static doubleFuzzify the input value by increasing it by a few ulps, but never past max.static floatFuzzify the input value by increasing it by a few ulps, but never past max.static doublerandomDoubleBetween(Random r, double min, double max) A random double betweenmin(inclusive) andmax(inclusive).static floatrandomFloatBetween(Random r, float min, float max) A random float betweenmin(inclusive) andmax(inclusive).private static longtoSortable(double value) private static inttoSortable(float value)
-
Field Details
-
EVIL_RANGE_LEFT
private static final int EVIL_RANGE_LEFT- See Also:
-
EVIL_RANGE_RIGHT
private static final int EVIL_RANGE_RIGHT- See Also:
-
EVIL_VERY_CLOSE_RANGE_ENDS
private static final int EVIL_VERY_CLOSE_RANGE_ENDS- See Also:
-
EVIL_ZERO_OR_NEAR
private static final int EVIL_ZERO_OR_NEAR- See Also:
-
EVIL_SIMPLE_PROPORTION
private static final int EVIL_SIMPLE_PROPORTION- See Also:
-
EVIL_RANDOM_REPRESENTATION_BITS
private static final int EVIL_RANDOM_REPRESENTATION_BITS- See Also:
-
-
Constructor Details
-
BiasedNumbers
public BiasedNumbers()
-
-
Method Details
-
randomDoubleBetween
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
Fuzzify the input value by decreasing it by a few ulps, but never past min. -
fuzzUp
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
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
Fuzzify the input value by decreasing it by a few ulps, but never past min. -
fuzzUp
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)
-