Generating a categorical value

Generation of a random value from a categorical distribution can be based on 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.)

The diagram below illustrates generation of a random result from a tennis match in which player Blue has probability 0.6 of beating player White.

Click Generate value to find a rectangularly distributed value. If this value is less than 0.6, a categorical value Blue wins is generated; otherwise White wins is generated.

Repeat several times and observe that approximately 60% of the values generated are Blue wins.


The next diagram shows how a random value can be generated from a categorical distribution with more than two possible categories.

Click Next Value to generate a random eye colour. Select Hair colour from the pop-up menu to generate random hair colours.