apoc.coll.randomItems

Details

Syntax

apoc.coll.randomItems(coll, itemCount [, allowRepick ])

Description

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).

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to return random items from.

itemCount

INTEGER

The number of random items to return from the list.

allowRepick

BOOLEAN

Whether elements from the original list can be selected more than once. The default is: false.

Returns

LIST<ANY>

Usage examples

The following returns 2 random values from a list:

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

[5, 3]