Did you know ... | Search Documentation: |
library(random): Random numbers |
random(10)
This library is derived from the DEC10 library random. Later, the core random generator was moved to C. The current version uses the SWI-Prolog arithmetic functions to realise this library. These functions are based on the GMP library.
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.
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.|
List|
), followed by nth1/3.
Fails of List is the empty list.
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.
|
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].
randseq(K, N, List) :- randset(K, N, Set), random_permutation(Set, List).
type_error(list, _)
.