ec.util
Class RandomChoice
java.lang.Object
|
+--ec.util.RandomChoice
- public class RandomChoice
- extends java.lang.Object
Method Summary |
static void |
organizeDistribution(double[] probabilities)
Normalizes probabilities, then converts them into continuing
sums. |
static void |
organizeDistribution(float[] probabilities)
Normalizes probabilities, then converts them into continuing
sums. |
static void |
organizeDistribution(java.lang.Object[] objs,
RandomChoiceChooser chooser)
Normalizes the probabilities associated
with an array of objects, then converts them into continuing
sums. |
static int |
pickFromDistribution(double[] probabilities,
double prob,
int checkboundary)
Picks a random item from an array of probabilities,
normalized and summed as follows: For example,
if four probabilities are {0.3, 0.2, 0.1, 0.4}, then
they should get normalized and summed by the outside owners
as: {0.3, 0.5, 0.6, 1.0}. |
static int |
pickFromDistribution(float[] probabilities,
float prob,
int checkboundary)
Picks a random item from an array of probabilities,
normalized and summed as follows: For example,
if four probabilities are {0.3, 0.2, 0.1, 0.4}, then
they should get normalized and summed by the outside owners
as: {0.3, 0.5, 0.6, 1.0}. |
static int |
pickFromDistribution(java.lang.Object[] objs,
RandomChoiceChooser chooser,
float prob,
int checkboundary)
Picks a random item from an array of objects, each with an
associated probability that is accessed by taking an object
and passing it to chooser.getProbability(obj). |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
RandomChoice
public RandomChoice()
organizeDistribution
public static void organizeDistribution(float[] probabilities)
- Normalizes probabilities, then converts them into continuing
sums. This prepares them for being usable in pickFromDistribution.
If the probabilities are all 0, or any of them are negative,
then an ArithmeticException is thrown.
For example,
{0.6, 0.4, 0.2, 0.8} -> {0.3, 0.2, 0.1, 0.4} -> {0.3, 0.5, 0.6, 1.0}
organizeDistribution
public static void organizeDistribution(double[] probabilities)
- Normalizes probabilities, then converts them into continuing
sums. This prepares them for being usable in pickFromDistribution.
If the probabilities are all 0, or any of them are negative,
then an ArithmeticException is thrown.
For example,
{0.6, 0.4, 0.2, 0.8} -> {0.3, 0.2, 0.1, 0.4} -> {0.3, 0.5, 0.6, 1.0}
organizeDistribution
public static void organizeDistribution(java.lang.Object[] objs,
RandomChoiceChooser chooser)
- Normalizes the probabilities associated
with an array of objects, then converts them into continuing
sums. This prepares them for being usable in pickFromDistribution.
If the probabilities are all 0, or any of them are negative,
then an ArithmeticException is thrown.
For example,
{0.6, 0.4, 0.2, 0.8} -> {0.3, 0.2, 0.1, 0.4} -> {0.3, 0.5, 0.6, 1.0}
The probabilities are retrieved and set using chooser.
pickFromDistribution
public static int pickFromDistribution(float[] probabilities,
float prob,
int checkboundary)
- Picks a random item from an array of probabilities,
normalized and summed as follows: For example,
if four probabilities are {0.3, 0.2, 0.1, 0.4}, then
they should get normalized and summed by the outside owners
as: {0.3, 0.5, 0.6, 1.0}. If probabilities.length < checkboundary,
then a linear search is used, else a binary search is used.
pickFromDistribution
public static int pickFromDistribution(double[] probabilities,
double prob,
int checkboundary)
- Picks a random item from an array of probabilities,
normalized and summed as follows: For example,
if four probabilities are {0.3, 0.2, 0.1, 0.4}, then
they should get normalized and summed by the outside owners
as: {0.3, 0.5, 0.6, 1.0}. If probabilities.length < checkboundary,
then a linear search is used, else a binary search is used.
pickFromDistribution
public static int pickFromDistribution(java.lang.Object[] objs,
RandomChoiceChooser chooser,
float prob,
int checkboundary)
- Picks a random item from an array of objects, each with an
associated probability that is accessed by taking an object
and passing it to chooser.getProbability(obj). The objects'
probabilities are
normalized and summed as follows: For example,
if four probabilities are {0.3, 0.2, 0.1, 0.4}, then
they should get normalized and summed by the outside owners
as: {0.3, 0.5, 0.6, 1.0}. If probabilities.length < checkboundary,
then a linear search is used, else a binary search is used.