eu.gressly.hw.math.random

Class WalkerCategories

public class WalkerCategories extends Object implements WeightedRandomCategories

Returns a category number with a given probability. Categories are numbered starting at 0 (zero) ending at "n-1". Example:
  
   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
intgetNrOfCategories()
static voidmain(String[] args)
For test purpose only.

Constructor Detail

WalkerCategories

public WalkerCategories(double[] weights)
See example in the class documentation.

Method Detail

getNrOfCategories

public int getNrOfCategories()

main

public static void main(String[] args)
For test purpose only.