RANDOM_STRING

Returns a string of random characters. The function takes three optional arguments: length, mode, and custom.

length determines the length of the string (default 16).

mode determines the type of characters in the string. The options are "alphanumeric", "custom", "hex", "letters", "numbers" (default "alphanumeric").

The custom_characters argument is only used when mode is set to "custom". It is a string of characters that will be used to generate the random string.

Syntax 

RANDOM_STRING(length, mode, custom_characters)

Usage examples 

Example 1

Returns a string of random upper and lowercase letters and numbers (a-z, A-Z, and 0-9).

Formula

RANDOM_STRING()

Output

"aBcDeFgH12345678"

Example 2

Returns a string of random alphanumeric characters of set length.

Formula

RANDOM_STRING(32)

Output

"aBcDeFgHiJkLmNoP1234567890123456"

Example 3

In "hex" mode, returns a string of random lowercase hexadecimal characters (0-9 and a-f).

Formula

RANDOM_STRING(16, "hex")

Output

"aa1bb2cc3dd4ee5f"

Example 4

In "letters" mode, returns a string of random uppercase and lowercase letters (a-z and A-Z).

Formula

RANDOM_STRING(52, "letters")

Output

"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Example 5

In "numbers" mode, returns a string of random digits (0-9).

Formula

RANDOM_STRING(32, "numbers")

Output

"01234567890123456789012345678901"

Example 6

In "custom" mode, returns a string of random characters from the provided string.

Formula

RANDOM_STRING(10, "custom", "abc123")

Output

"a1b2c3a2c1"

Example 7

"custom" mode also accepts special characters and emojis.

Formula

RANDOM_STRING(10, "custom", "a1&👍")

Output

"a1&👍👍&1a&1"
Was this helpful?