
Uncommons Maths API (Version 1.2.3) 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object java.lang.Number org.uncommons.maths.random.Probability
public final class Probability
Immutable value type for probabilities. Forces numeric probabilities to be within the range 0..1 inclusive and provides useful utility methods for working with probabilities (such as generating an event with a given probability).
Field Summary  

static Probability 
EVENS
Convenient constant representing a probability of 0.5 (used to model an event that has a 50/50 chance of occurring). 
static Probability 
ONE
Convenient constant representing a probability of one. 
static Probability 
ZERO
Convenient constant representing a probability of zero. 
Constructor Summary  

Probability(double probability)

Method Summary  

int 
compareTo(Probability other)
Compares this value with the specified object for order. 
double 
doubleValue()
Returns the probability value as a double. 
boolean 
equals(Object other)
Determines whether this probability value is equal to some other object. 
float 
floatValue()
Returns the probability value as a float. 
Probability 
getComplement()
The complement of a probability p is 1  p. 
int 
hashCode()
Overridden to be consistent with equals(Object) . 
int 
intValue()
Converting a fractional probability into an integer is not meaningful since all useful information is discarded. 
long 
longValue()
Converting a fractional probability into an integer is not meaningful since all useful information is discarded. 
boolean 
nextEvent(Random rng)
Generates an event according the probability value p. 
String 
toString()
Formats the probability as a String. 
Methods inherited from class java.lang.Number 

byteValue, shortValue 
Methods inherited from class java.lang.Object 

clone, finalize, getClass, notify, notifyAll, wait, wait, wait 
Field Detail 

public static final Probability ZERO
ONE
,
EVENS
public static final Probability EVENS
ZERO
,
ONE
public static final Probability ONE
ZERO
,
EVENS
Constructor Detail 

public Probability(double probability)
probability
 The probability value (a number in the range 0..1 inclusive). A
value of zero means that an event is guaranteed not to happen. A value of 1 means
it is guaranteed to occur.Method Detail 

public boolean nextEvent(Random rng)
rng
 A source of randomness for generating events.
public Probability getComplement()
public int intValue()
ArithmeticException
, except when the probability is exactly
zero or one.
intValue
in class Number
ArithmeticException
 Unless the probability is exactly zero or one.public long longValue()
ArithmeticException
, except when the probability is exactly
zero or one.
longValue
in class Number
ArithmeticException
 Unless the probability is exactly zero or one.public float floatValue()
floatValue
in class Number
public double doubleValue()
doubleValue
in class Number
public boolean equals(Object other)
equals
in class Object
other
 The object to compare against.
public int hashCode()
equals(Object)
.
hashCode
in class Object
public int compareTo(Probability other)
compareTo
in interface Comparable<Probability>
other
 Another Probability value.
public String toString()
toString
in class Object

Uncommons Maths API (Version 1.2.3) 

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 