apoc.coll.randomItem

Details

Syntax

apoc.coll.randomItem(coll)

Description

Returns a random item from the LIST<ANY>, or null on LIST<NOTHING> or LIST<NULL>.

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to return a random item from.

Returns

ANY

Usage examples

The following examples return a random value from a list using both APOC and Cypher:

apoc.coll.randomItem
RETURN apoc.coll.randomItem([1,3,5,7,9]) AS output;
Using Cypher’s rand()
WITH [1,3,5,7,9] AS list
WITH list, toInteger(rand() * size(list)) AS randomInt
RETURN list[randomInt] AS output
Results
output

7