SWI-Prolog.
It came to mind such a decision. Get a random alternative from generating permutations in non-lexicographical order.
position(L,X,[X|L]). position([H|T1],X,[H|T2]):-position(T1,X,T2). transposition([],[]). transposition([H|T],L):- transposition(T,T1), position(T1,H,L). % fixed permutation permutation(In, Out) :- len(In, Length), fact(Length, Count), permutation(In, Out, Count), !. permutation(_, _, 0):-!. permutation(In, Out, Count) :- Count > 0, transposition(In, Out), rand(Stop, 0, 10), write(Count), nl, Stop < 5, Count1 is Count - 1, permutation(In, Out, Count1); Stop >=5,!.
How to make this program stop when Stop> = 5 for example.