protocol
random_protocol
Random number generator protocol. The predicates are declared as synchronized when the library is compiled using a backend supporting threads.
logtalk_load(random(loader))staticPublic predicates
random/1
Returns a new random float value in the interval [0.0, 1.0[.
static, synchronizedrandom(Random)random(-float) - onebetween/3
Returns a new random integer in the interval [Lower, Upper]. Fails if Lower or Upper are not integers or if Lower > Upper.
staticbetween(Lower,Upper,Random)between(+integer,+integer,-integer) - zero_or_onemember/2
Returns a random member of a list. Fails if the list is empty.
staticmember(Random,List)member(-term,+list(term)) - zero_or_oneselect/3
Returns a random member of a list and the rest of the list. Fails if the list is empty.
staticselect(Random,List,Rest)select(-term,+list(term),-list(term)) - zero_or_oneselect/4
Returns a random member of a list, replacing it with a new element and returning the resulting list.
staticselect(Random,OldList,New,NewList)select(-term,+list(term),@term,-list(term)) - zero_or_oneswap/2
Swaps two randomly selected elements of a list. Fails if the list is empty or contains a single element.
staticswap(OldList,NewList)swap(-term,+list(term)) - zero_or_oneswap_consecutive/2
Swaps two randomly selected consecutive elements of a list. Fails if the list is empty or contains a single element.
staticswap_consecutive(OldList,NewList)swap_consecutive(-term,+list(term)) - zero_or_oneenumerate/2
Enumerates the elements of a list in random order. Fails if the list is empty.
staticenumerate(List,Random)enumerate(+list(term),--term) - zero_or_moresample/3
Returns a random sample without replacement, preserving source order and element identity. Returns the whole list when the requested size is at least its length.
staticsample(List,Size,Sample)sample(+list,+non_negative_integer,-list) - onesample/4
Returns a random sample without replacement using the supplied list length, preserving source order and element identity. The supplied length must equal the actual list length and is not verified. Returns the whole list when the requested size is at least its length.
staticsample(List,Length,Size,Sample)sample(+list,+non_negative_integer,+non_negative_integer,-list) - onepermutation/2
Returns a random permutation of a list.
static, synchronizedpermutation(List,Permutation)permutation(+list,-list) - onesequence/4
Returns list of random integers of given length in random order in interval [Lower, Upper]. Fails if Length, Lower, or Upper are not integers or if Lower > Upper.
static, synchronizedsequence(Length,Lower,Upper,List)sequence(+integer,+integer,+integer,-list(integer)) - zero_or_oneset/4
Returns ordered set of random integers of given size in interval [Lower, Upper]. Fails if Length, Lower, or Upper are not integers, if Lower > Upper, or if Length > Upper - Lower + 1.
static, synchronizedset(Length,Lower,Upper,Set)set(+integer,+integer,+integer,-list(integer)) - zero_or_onerandom/3
Returns a new random value in the interval [Lower, Upper[. Fails if Lower > Upper. Deprecated. Use between/3 for integers.
static, synchronizedrandom(Lower,Upper,Random)random(+integer,+integer,-integer) - zero_or_onerandom(+float,+float,-float) - zero_or_onerandseq/4
Returns list of random values of given length in random order in interval [Lower, Upper[. Fails if Lower > Upper or if the arguments are neither integers or floats. Deprecated. Use sequence/4 for integers.
static, synchronizedrandseq(Length,Lower,Upper,List)randseq(+integer,+integer,+integer,-list(integer)) - zero_or_onerandseq(+integer,+float,+float,-list(float)) - zero_or_onerandset/4
Returns ordered set of random values of given size in interval [Lower, Upper[. Fails if the arguments are neither integers or floats, Lower > Upper, or Length > Upper - Lower when arguments are integers. Deprecated. Use set/4 for integers.
static, synchronizedrandset(Length,Lower,Upper,Set)randset(+integer,+integer,+integer,-list(integer)) - zero_or_onerandset(+integer,+float,+float,-list(float)) - zero_or_onemaybe/0
Succeeds or fails with equal probability.
staticmaybe - zero_or_onemaybe/1
Succeeds with probability Probability or fails with probability 1 - Probability. Fails if Probability is not a float or is outside the interval [0.0, 1.0].
staticmaybe(Probability)maybe(+probability) - zero_or_onemaybe/2
Succeeds with probability K/N where K and N are integers satisfying the equation 0 =< K =< N. Fails otherwise.
staticmaybe(K,N)maybe(+non_negative_integer,+non_negative_integer) - zero_or_onemaybe_call/1
Calls a goal or fails without calling it with equal probability. When the goal is called, it determines if this predicate succeeds once or fails.
staticmaybe_call(Goal)maybe_call(0)maybe_call(+callable) - zero_or_onemaybe_call/2
Calls a goal or fails without calling it with probability Probability. When the goal is called, it determines if this predicate succeeds once or fails.
staticmaybe_call(Probability,Goal)maybe_call(*,0)maybe_call(+probability,+callable) - zero_or_oneProtected predicates
(none)
Private predicates
(none)
Operators
(none)
See also