Generating a categorical value
A value from a categorical distribution can be generated from a rectangularly distributed random value, r . If the categorical distribution has two possible values, success and failure, and the probability of success is denoted by the symbol π, then a success will be generated if r is less than π.
If there are more than two possible categories in the distribution, the method can be easily extended. Each possible value corresponds to a range of values of r whose width equals the required probability. (Note that all probabilities for a categorical distribution must sum to 1.0.)
Random success or failure
We first describe how a random success or failure can be generated.
Random values from other categorical distributions
A similar method can be used to generate categorical values from other distributions.