casep* ( assoc -- quot )
Random combinators

Prev:casep ( assoc -- quot )
Next:call-random ( seq -- quot )


Vocabulary
combinators.random

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


Outputs
None

Word description
Calls the different quotations randomly with the given probability. Unlike casep, the probabilities are interpreted as conditional probabilities. All probabilities must be numbers between 0 and 1. The sequence must end with a pair whose probability is one, or a quotation.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.5 probability, 2 with 0.25 probability and 3 with 0.25 probability
USING: combinators.random prettyprint ; { { 0.5 [ 1 ] } { 0.5 [ 2 ] } { 1 [ 3 ] } } casep* .


USING: combinators.random prettyprint ; { { 0.5 [ 1 ] } { 0.5 [ 2 ] } [ 3 ] } casep* .


See also
casep

Definition