Vocabulary
combinators.random

Inputs
assoca sequence of probability/quotations pairs with an optional quotation at the end


Outputs
None

Word description
Calls the different quotations randomly with the given probability. The optional quotation at the end will be given a probability so that the sum of the probabilities is one. Therefore, the sum of the probabilities must be exactly one when no default quotation is given, or between zero and one when it is given. Additionally, all probabilities must be numbers between 0 and 1. These rules are enforced during the macro expansion by throwing bad-probabilities if they are not respected.

Examples
The following two forms will output 1 with 0.2 probability, 2 with 0.3 probability and 3 with 0.5 probability
USING: combinators.random prettyprint ; { { 0.2 [ 1 ] } { 0.3 [ 2 ] } { 0.5 [ 3 ] } } casep .


USING: combinators.random prettyprint ; { { 0.2 [ 1 ] } { 0.3 [ 2 ] } [ 3 ] } casep .


See also
casep*

Definition