☰

*ON THIS PAGE*# Randomized aggregates

**Author(s):** Jose F. Morales.

## Usage and interface

## Documentation on exports

`random_findall(K,X,Goal,Ys)`
*Meta-predicate* with arguments: `random_findall(?,?,goal,?)`.

## Documentation on imports

This module has the following direct dependencies:

This module implements randomized version of aggregates predicates.

Example 1:

?- random_findall(4, X, between(1,10000,X), Xs). Xs = [6659,7135,7871,9864] ? yes

Example 2:

?- random_findall(4, X, member(X, [the,sequel,will,not,happen]), Xs). Xs = [the,sequel,will,happen] ? yes

**Library usage:**`:- use_module(library(random_aggregates)).`**Exports:***Predicates:*`random_findall/4`.

PREDICATErandom_findall/4

This predicate implements the reservoir sampling algorithm. It needs to evaluate all solutions to Goal but only need to keeps K of those solutions in memory simultaneously.

Usage:`random_findall(K,X,Goal,Ys)`

Obtains a list Ys of length K of random solutions uniformly distributed from X for all solutions to Goal. Fails if there are less than K solutions.

*The following properties should hold at call time:*

(`term_typing:nonvar/1`)K is currently a term which is not a free variable.

(`term_typing:nonvar/1`)X is currently a term which is not a free variable.

(`term_typing:nonvar/1`)Goal is currently a term which is not a free variable.

*System library modules:*`native_props`,`datafacts_rt`,`aggregates`,`random`.*Packages:*`prelude`,`initial`,`condcomp`,`assertions`,`assertions/assertions_basic`,`isomodes`,`nativeprops`,`hiord`,`datafacts`.

Generated with LPdoc using Ciao