apoc.coll.randomItems

Function

apoc.coll.randomItems(coll LIST<ANY>, itemCount INTEGER, allowRepick BOOLEAN) - returns a LIST<ANY> of itemCount random items from the original LIST<ANY> (optionally allowing elements in the original LIST<ANY> to be selected more than once).

Signature

apoc.coll.randomItems(coll :: LIST<ANY>, itemCount :: INTEGER, allowRepick = false :: BOOLEAN) :: LIST<ANY>

Input parameters

Name Type Default

coll

LIST<ANY>

null

itemCount

INTEGER

null

allowRepick

BOOLEAN

false

Usage examples

The following returns 2 random values from a list:

RETURN apoc.coll.randomItems([1,3,5,7,9], 2) AS output;
Table 1. Results
Output

[5, 3]