[ library(tentative) | Reference Manual | Alphabetic Index ]
random_element(+Values, -X)
Pick random element from range or collection
- Values
- Specification of possible values
- X
- Output variable
Description
Select a random value from the given specification of possible
values. The Values specification can be
- Min..Max
- A range of integers from Min to Max
- List
- A list of possible values
- Array
- An array of possible values
Modes and Determinism
- random_element(+, -) is semidet
Fail Conditions
The range specification is empty or invalid
Examples
?- random_element(3 .. 7, X).
X = 5
Yes (0.00s cpu)
?- random_element([a, b, c, d], X).
X = a
Yes (0.00s cpu)
?- random_element([](a, b, c, d), X).
X = c
Yes (0.00s cpu)
See Also
random / 1, frandom / 1, random_sample / 3, tent_set_random / 2