projog

4.14. random(X) Evaluate to a random integer i for which 0 =< i < X.

Examples

validate_in_range(X) :- Y is random(X), Y>=0, Y<X.

?- validate_in_range(3), validate_in_range(7), validate_in_range(100).

yes

?- X is random(1).
X = 0

yes

test_max_random(X) :- X is random(9223372036854775807), X>=0, X<9223372036854775807.

?- test_max_random(X), test_max_random(Y), integer(X), integer(Y), X=\=Y, write(here), fail.
here
no