Query/set the state of the random generator. This is intended
for restarting the generator at a known state only. The
predicate setrand/1 accepts an opaque term returned by
getrand/1. This term may be asserted, written and read. The
application may not make other assumptions about this term.
For compatibility reasons with older versions of this library,
setrand/1 also accepts a term rand(A,B,C)
, where A, B and C are
integers in the range 1..30,000. This argument is used to seed
the random generator. Deprecated.
- Errors
- -
existence_error(random_state, _)
is raised if the
underlying infrastructure cannot fetch the random state.
This is currently the case if SWI-Prolog is not compiled
with the GMP library.
- See also
- - set_random/1 and random_property/1 provide the SWI-Prolog
native implementation.
Selects a random subsequence Subseq of List, with Complement
containing all elements of List that were not selected. Each element
of List is included with equal probability in either Subseq or
Complement.
random_subseq/3 may also be called with Subseq and Complement bound
and List unbound, which will recreate List by randomly interleaving
Subseq and Complement. This mode may fail randomly, matching SICStus
behavior. The failure probability corresponds to the probability of
the "forward" mode selecting a Subseq/Complement combination with
different lengths.
- Compatibility
- - SICStus 4
S is a sorted list of K unique random integers in the range 1..N.
The implementation uses different techniques depending on the ratio
K/N. For small K/N it generates a set of K random numbers, removes
the duplicates and adds more numbers until |S| is K. For a large K/N
it enumerates 1..N and decides randomly to include the number or
not. For example:
?- randset(5, 5, S).
S = [1, 2, 3, 4, 5]. (always)
?- randset(5, 20, S).
S = [2, 7, 10, 19, 20].
- See also
- - randseq/3.
S is a list of K unique random integers in the range 1..N. The
order is random. Defined as
randseq(K, N, List) :-
randset(K, N, Set),
random_permutation(Set, List).
- See also
- - randset/3.