public final class Probability extends java.lang.Number implements java.lang.Comparable<Probability>
| Modifier and Type | Field and Description |
|---|---|
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 and Description |
|---|
Probability(double probability) |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Probability other)
Compares this value with the specified object for order.
|
double |
doubleValue()
Returns the probability value as a double.
|
boolean |
equals(java.lang.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()
Over-ridden 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(java.util.Random rng)
Generates an event according the probability value p.
|
java.lang.String |
toString()
Formats the probability as a String.
|
public static final Probability ZERO
public static final Probability EVENS
public static final Probability ONE
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.public boolean nextEvent(java.util.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 java.lang.Numberjava.lang.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 java.lang.Numberjava.lang.ArithmeticException - Unless the probability is exactly zero or one.public float floatValue()
floatValue in class java.lang.Numberpublic double doubleValue()
doubleValue in class java.lang.Numberpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectother - The object to compare against.public int hashCode()
equals(Object).hashCode in class java.lang.Objectpublic int compareTo(Probability other)
compareTo in interface java.lang.Comparable<Probability>other - Another Probability value.public java.lang.String toString()
toString in class java.lang.Object