maybe this could help, in assumption you're actually required to generate facts:
:- dynamic(pit/2).
pit(1,1).
pit(1,2).
pit(2,1).
placePit(N) :-
N > 0,
Px is random(4)+1,
Py is random(4)+1,
( \+ pit(Px, Py) % if not exist
-> assertz(pit(Px, Py)), % store
M is N-1 % generate another
; M = N % nothing changed, retry
),
placePit(M). % recursion is the proper Prolog way to do cycles
placePit(0). % end of recursion (we call it 'base case')
you should call as
?- placePit(3).
It shows a bit of syntactic detail, like the 'if/then/else', that in Prolog has a peculiar form.
edit When done, you could remove unwanted pit/2, to get your db 'clean'.
?- maplist(retract, [pit(1,1),pit(1,2),pit(2,1)]).
(note that I assumed - based on your description - that a DB stored pit/2 was of value for further processing).