I know I can do X is random(10).
to get a random number from 0 to 10, but is there a similar command to get a random matching item?
You can implement it. Here is a version:
%% choose(List, Elt) - chooses a random element
%% in List and unifies it with Elt.
choose([], []).
choose(List, Elt) :-
length(List, Length),
random(0, Length, Index),
nth0(Index, List, Elt).
From http://ozone.wordpress.com/2006/02/22/little-prolog-challenge/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With