Tiago Santos
Tiago Santos

Reputation: 173

Choose random numbers

I have this function:

:- use_module(library(random)).

choose(A, C, B) :- B is random(A), (B\=2, choose(A,C,B));(B == 2, !).

How can I make this function generate numbers from 0 to A, different from C and save the result in B?

Thanks.

Upvotes: 2

Views: 249

Answers (1)

CapelliC
CapelliC

Reputation: 60034

should be

choose(A, C, B) :- repeat, B is random(A), B \= C, !.

Upvotes: 1

Related Questions