eu.gressly.hw.math.random
public class WalkerCategories extends Object implements WeightedRandomCategories
WalkerCategories wc;
double [] wghts = new double[] {2,5,3};
wc = new WalkerCategories(wghts);
// ... later : ...
int kat = wc.getWeightedCategory(Math.random());
After execution of the above code, the variable "kat" will
have a value of 0, 1 or 2 with probabilities 20%, 50% or 30%
respectively.
Original code by A. J. Walker 1977 (see Knuth, "The art of computer programing vol. 2"
| Constructor Summary | |
|---|---|
| WalkerCategories(double[] weights)
See example in the class documentation. | |
| Method Summary | |
|---|---|
| int | getNrOfCategories() |
| static void | main(String[] args)
For test purpose only. |