public final class Probability extends Number implements 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(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(Random rng)
Generates an event according the probability value p.
|
String |
toString()
Formats the probability as a String.
|
byteValue, shortValue
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(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)
public int hashCode()
equals(Object)
.public int compareTo(Probability other)
compareTo
in interface Comparable<Probability>
other
- Another Probability value.public String toString()
Copyright © 2015. All rights reserved.