eu.gressly.hw.math.random

Interface WeightedRandomCategories

public interface WeightedRandomCategories

Weighted random categories. Source: Walker s. Knuth II (seminumerical algorithms). Example: (eg. WalkerCategories as implementing class) wghts = new double [] {20, 50, 30, 20}; WalkerCategories wc = new WalkerCategories(wghts); int cat = wc.getWeightedCategory(Math.random()); // cat will be 0, 1, 2, 3 with probabilities 20:50:30:20
Method Summary
intgetWeightedCategory(double uniform01)
Returns the number [0 .. n-1] of a category.

Method Detail

getWeightedCategory

public int getWeightedCategory(double uniform01)
Returns the number [0 .. n-1] of a category. The weights and count of the categories will be given in the impementing class.

Parameters: uniform01 specifies a uniform distributed random number between 0 (inkl.) and 1 (exkl.)

Returns: Category number 0 .. n-1