Trying to write something like generate(L, N) that will generate a list L of size N where each element is either a 0 or a 1. This is what I have but it doesn't work, any suggestions?
generate(L, 0) :- !.
generate(L, N) :- A is N - 1, B is random(2), generate([B|L], A).
I also tried something like this that didn't work either
generate(L, 0) :- !.
generate(L, N) :- A is N - 1, B is random(2), append(L, B, C), generate(C, A).
generate(L, 0) :- !.
generate(L, N) :- A is N - 1, B is random(2), generate([B|L], A).
I also tried something like this that didn't work either
generate(L, 0) :- !.
generate(L, N) :- A is N - 1, B is random(2), append(L, B, C), generate(C, A).