apoc.text.random

Details

Syntax

apoc.text.random(length [, valid ])

Description

Generates a random STRING to the given length using a length parameter and an optional STRING of valid characters. Unsuitable for cryptographic use-cases.

Arguments

Name

Type

Description

length

INTEGER

The length of the random string.

valid

STRING

The valid characters the random string can contain. The default is: A-Za-z0-9.

Returns

STRING

Usage Examples

You can generate a random string to a specified length by calling apoc.text.random with a length parameter and optional string of valid characters.

The valid parameter will accept the following regex patterns, alternatively you can provide a string of letters and/or characters.

Pattern

Description

A-Z

A-Z in uppercase

a-z

A-Z in lowercase

0-9

Numbers 0-9 inclusive

The following call will return a random string including uppercase letters, numbers and . and $ characters.

RETURN apoc.text.random(10, "A-Z0-9.$") AS output;
Results
output

"V9Y7N54LO6"