Skip to main content

Random String

Text Processing Data Generation

Synopsis

Generates random strings with specified length and character sets.

Schema

- random_string:
target_field: <ident>
length: <numeric>
charset: <enum>
custom_chars: <string>
description: <text>
if: <script>
ignore_failure: <boolean>
on_failure: <processor[]>
on_success: <processor[]>
tag: <string>

Configuration

The following fields are used to define the processor:

FieldRequiredDefaultDescription
target_fieldY-Field to store the generated string. There is no default: an empty value fails with target_field is required
lengthY-Length of the string to generate. Must be greater than 0
charsetNalphanumericCharacter set: alphanumeric, alpha (or alphabetic), numeric (or numbers, digits), hex (or hexadecimal), base64, or custom
custom_charsY*-The characters to draw from. Required when charset is custom, unused otherwise
descriptionN-Explanatory note
ifN-Condition to run
ignore_failureNfalseContinue processing if generation fails
on_failureN-See Handling Failures
on_successN-See Handling Success
tagN-Identifier
disabledNfalseWhen true, the processor is skipped and the event continues to the next one. Lets you take a processor out of the path without removing its configuration

* = Required only when charset is custom; the processor then fails with custom_chars must be specified when charset is 'custom' if it is absent.

Details

Generates cryptographically secure random strings using specified character sets and length requirements. This processor is useful for creating unique identifiers, tokens, passwords, or test data.

The processor supports various predefined character sets and allows custom character sets for specific requirements. Generated strings are suitable for security-sensitive applications.

note

The processor uses cryptographically secure random number generation to ensure unpredictability of the generated strings. This makes them suitable for security tokens and identifiers.

The prefix and suffix options allow you to add static text before and after the random portion, which is useful for creating formatted identifiers or tokens with specific patterns.

warning

Generating very long random strings (>10000 characters) may impact performance. Consider using reasonable lengths for production workloads.

Details

The processor takes no input field. It generates a value and writes it, so there is nothing to read and no ignore_missing.

There is no prefix or suffix. To wrap the generated value, follow this processor with a Set or Append step that builds the final string from it.

Each charset name has aliases: alpha also accepts alphabetic, numeric also accepts numbers and digits, and hex also accepts hexadecimal. An unrecognized name is an error rather than a silent fallback.

Examples

Basic Random String

Generating an alphanumeric identifier...

- random_string:
target_field: session_id
length: 16

with the default charset:

{
"session_id": "k3Jd8Ba9Xq2Lm5Zt"
}

Hexadecimal Token

A hexadecimal string of a fixed width...

- random_string:
target_field: request.token
length: 32
charset: hex

drawn from 0-9 and a-f:

{
"request": {"token": "9f2c7a10b4e83d5619cf07ab2e4d8163"}
}

A Prefixed Identifier

There is no prefix option, so build the final value in a second step...

- random_string:
target_field: _suffix
length: 8
charset: numeric
- set:
field: transaction_id
value: "TXN-{{_suffix}}"
- remove:
field: _suffix

with the scratch field removed once it has been used:

{
"transaction_id": "TXN-40718392"
}

A Custom Alphabet

charset: custom draws from the characters you supply...

- random_string:
target_field: voucher
length: 10
charset: custom
custom_chars: "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"

here excluding the characters that are easily misread aloud:

{
"voucher": "H7QK2ZN9RT"
}

Base64 Alphabet

The base64 charset draws from the base64 alphabet...

- random_string:
target_field: nonce
length: 24
charset: base64

note this is a random string OF those characters, not an encoding of anything:

{
"nonce": "Qm9uY2VkVmFsdWVYYTdLOTI="
}