apoc.coll.randomItems

Function

apoc.coll.randomItems(coll [Any], itemCount Integer, allowRepick Boolean) - returns a list of itemCount random items from the original list (optionally allowing elements in the original list to be selected more than once).

Signature

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

Input parameters

Name Type Default

coll

LIST? OF 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]