Q:

How can you access different positions of a list in Prolog?

I have the following Prolog program:
father(person1,person2).
mother(person3,person2).

 say_hi(X) :- father(X,person1) , write('Hello1').
 say_hi(X) :- father(X,person2) , write('Hello2').

I want to have a list of different sentences: the program should return  different sentences each time that you call say_hi
So , the expected output of the program should be:
 ?- say_hi(person1)
 Hello1
 ?- say_hi(person1)
 Hello3
 ?- say_hi(person4)
 Hello4

The different elements of the list should be written in a random way 

A:

If you want just once each list' element, here is a possible definition (in SWI-Prolog), that returns elements on backtracking:
get_random([E], E) :- !.
get_random(L, E) :-
    length(L, C),
    R is random(C),
    length(Skip, R),
    append(Skip, [X|Tail], L),
    ( E = X
    ; append(Skip, Tail, Rest),
      get_random(Rest, E) ).

test:
?- get_random([a,b,c,d,e,f],X).
X = e ;
X = f ;
X = d ;
X = b ;
X = c ;
X = a.

