Package com.github.tommyettinger.random
Enum Class DistributedRandom.ReductionMode
java.lang.Object
java.lang.Enum<DistributedRandom.ReductionMode>
com.github.tommyettinger.random.DistributedRandom.ReductionMode
- All Implemented Interfaces:
Serializable
,Comparable<DistributedRandom.ReductionMode>
,Constable
- Enclosing class:
- DistributedRandom
One of two possible modes this can use to limit the range of a Distribution.
FRACTION
simply gets the
fractional part of a distribution by subtracting the floor from a result. CLAMP
uses
Math.min(double, double)
and Math.max(double, double)
to cap the values at both ends, inclusive
on 0.0 and exclusive on 1.0 .-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantDescriptionGets one distributed double and clamps it to 0.0 if it is less than 0.0, or to 0.9999999999999999 if it is 0.9999999999999999 or greater, then uses that.Gets one distributed double, gets the portion after the decimal point, and only uses that.Repeatedly attempts to get one distributed double, check if it is between 0.0 inclusive and 1.0 exclusive, and either return it if it is within range or get another distributed double and try again. -
Method Summary
Modifier and TypeMethodDescriptionabstract double
applyAsDouble
(Distribution dist) Returns the enum constant of this class with the specified name.static DistributedRandom.ReductionMode[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
FRACTION
Gets one distributed double, gets the portion after the decimal point, and only uses that. -
CLAMP
Gets one distributed double and clamps it to 0.0 if it is less than 0.0, or to 0.9999999999999999 if it is 0.9999999999999999 or greater, then uses that. -
REJECT
Repeatedly attempts to get one distributed double, check if it is between 0.0 inclusive and 1.0 exclusive, and either return it if it is within range or get another distributed double and try again. This is not guaranteed to complete for all distributions! While this can be the most correct ReductionMode for some distributions, use it with caution. Make sure theDistribution.getMinimum()
andDistribution.getMaximum()
allow results to be returned between 0 and 1.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
applyAsDouble
-