Reputation: 603
Simple question, how can I shuffle a list in Prolog, so that A1
is the shuffled list?
shuffle([1,1,1,2,3,4],A1),
I've tried a few predicates I found on the web but none of them seems to be working. Also found this but apparently it's not available anymore, according to SWI-Prolog.
Upvotes: 3
Views: 2878
Reputation: 4910
You can use random_permutation/2
. It is available in SWI-Prolog.
?- random_permutation([1,2,3],L).
L = [1, 3, 2].
Upvotes: 6