このディレクトリの索引
#  Why this predicate random_permutation doesn't work?
#  
#  http://www.swi-prolog.org/pldoc/doc_for?object=random_permutation/2
#  
#  ?- use_module(library(random)).
#  %  library(pairs) compiled into pairs 0.00 sec, 8,880 bytes
#  % library(random) compiled into random 0.04 sec, 333,032 bytes
#  true.
#  
#  ?- L=[1,2,3,4,5], random_permutation(L,P).
#  ERROR: toplevel: Undefined procedure: random_permutation/2 (DWIM could not correct goal)

random_permutation([],[]).
random_permutation(L1,[A|R2]) :-
        random_permutation(L1,R1,A),
        random_permutation(R1,R2).

random_permutation(L1,R1,A) :-
        length(L1,Len),
        Nth_0 is random mod Len,
        length(L0,Nth_0),
        append(L0,[A|R0],L1),
        append(L0,R0,R1).