

Note that random_member/2 doesn't backtrack like member/2 does. To achieve enumerating the list in random order, one can use something like
random_permutation([1,2,3], R), member(X, R)
.Did you know ... | Search Documentation: |
![]() | Predicate random_member/2 |
|
List|
), followed by nth1/3.
Fails of List is the empty list.
random_permutation([1,2,3], R), member(X, R)
.Typo:
Fails of List is the empty list.
to
Fails if List is the empty list.
This is not good (well, it it if you want to use random_member/2 to generate a stream of random booleans, but I think that's taking nondeterminism too far):
?- random_member(1,[1,2,3]). false. ?- random_member(1,[1,2,3]). true.
random_member(1,[1,2,3])
should succeed because 1 is, if not a "random" member, then at least a member of [1,2,3]