Randomize

Randomly select one item from a list

Node Type

Action

Category

Data Translation

Icon

Shuffle

Overview

The Randomize node is a utility node that randomly selects a single value from an input array. This powerful tool enables variety in your workflows, random decision-making, and unpredictable outcomes. Perfect for creating dynamic content, random sampling, or adding randomness to automated processes.

Key Features

  • Random Selection: Uses Math.random() for true randomness
  • Array Processing: Works with any array of string values
  • Complete Output: Returns selected value, index, and original array
  • Error Handling: Gracefully handles empty arrays and invalid inputs
  • Index Tracking: Provides the position of the selected item
  • Data Preservation: Maintains the original array for further processing

Prerequisites

Data Requirements

Understanding of array data structures and random selection needs

Array input with multiple values to choose from
Understanding of random selection use cases
Workflow design that can handle random outcomes

Use Case Planning

Random Selection: Identify where variety or unpredictability is needed
Array Processing: Plan how to handle the selected value and index
Workflow Logic: Design workflows that can work with random outcomes

Technical Requirements

Executable Node Framework: Access to node execution system
Array Support: System capable of processing array inputs
Random Generation: Access to Math.random() or equivalent

Node Configuration

Required Fields

Array

Type:text
Required:Yes
Value Type:array_string

The array to randomly select a value from. This must be a valid array variable or a comma separated list of values. The node will process this input and randomly select one item.

Optional Fields

The Randomize node has no optional fields. All configuration is handled through the single required input: the array to randomize from.

Technical Details

Random Selection Process

How the node processes arrays and generates random selections

Input Validation

The node first validates that the input is a valid array using Array.isArray(). If the input is not an array, it throws an error: "Input must be a valid array".

Empty Array Handling

If the input array is empty (length === 0), the node returns a special response with"No values in array" as the selected value and -1 as the index.

Random Index Generation

Uses Math.floor(Math.random() * arrayInput.length) to generate a random index between 0 and the array length (exclusive). This ensures equal probability for all array positions.

Output Structure

How the node formats and returns its results

Standard Output Format

Returns an array of ExecutableNodeValue objects, each with afieldKey and value.

Data Preservation

The original array is preserved exactly as provided, allowing downstream nodes to work with the complete dataset while still having access to the random selection results.

Error Handling

Comprehensive error handling ensures the node fails gracefully with clear error messages when invalid inputs are provided, preventing workflow crashes.

Examples & Use Cases

Random Content Selection

Select random content for dynamic generation

Use Case

Generate random social media posts, email subjects, or content variations to avoid repetitive messaging and increase engagement.

Configuration

{
  "array": ["Welcome to our platform!", "Thanks for joining us!", "We're excited to have you!", "Let's get started together!"]
}

This will randomly select one of the four welcome messages each time the workflow runs.

Workflow Structure

📝 Content Array → 🎲 Randomize → 📧 Email Generation → 📤 Send Email

A/B Testing

Randomly assign users to different test groups

Use Case

Randomly assign users to different test groups for A/B testing campaigns, ensuring unbiased distribution and statistically valid results.

Configuration

{
  "array": ["Group A", "Group B", "Control"]
}

This will randomly assign users to one of three test groups with equal probability.

Processing Steps

  • User data is processed for test assignment
  • Randomize node selects test group
  • User is assigned to selected group
  • Group assignment is recorded in database
  • User receives group-specific experience

Random Sampling

Select random items from large datasets

Use Case

Randomly sample items from large datasets for quality assurance, testing, or representative analysis without processing the entire dataset.

Configuration

{
  "array": ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8", "Item 9", "Item 10"]
}

This will randomly select one item from a dataset of 10 items for sampling purposes.

Sampling Workflow

📊 Large Dataset → 🎲 Randomize → 🔍 Quality Check → 📝 Sample Report

Benefits

  • Efficient Processing: Sample subset instead of full dataset
  • Statistical Validity: Random selection ensures representative samples
  • Cost Reduction: Lower processing costs for large datasets
  • Quick Results: Faster analysis and decision-making

Best Practices

Do's

  • • Use arrays with meaningful, related values
  • • Handle the case where arrays might be empty
  • • Use the selected index for tracking and debugging
  • • Preserve the original array for further processing
  • • Test with various array sizes and content types
  • • Consider the probability distribution of your selections
  • • Use for true randomness, not pseudo-random patterns

Don's

  • • Don't use for critical decision-making without validation
  • • Avoid extremely large arrays that might impact performance
  • • Don't assume the selection will always be different
  • • Avoid using for security-critical random number generation
  • • Don't forget to handle empty array edge cases
  • • Avoid mixing different data types in the same array
  • • Don't use for deterministic workflows
💡
Pro Tip: The Randomize node is perfect for adding variety to your workflows, but remember that true randomness means the same value can be selected multiple times in a row. If you need guaranteed variety, consider implementing additional logic to track previous selections.

Troubleshooting

Common Issues

Input Must Be a Valid Array Error

Symptoms: Node fails with "Input must be a valid array" error

Solution: Ensure your input is properly formatted as an array. Check that you're passing an array variable or a properly formatted comma-separated list. Verify the data type in your workflow context.

Empty Array Handling

Symptoms: Node returns "No values in array" and index -1

Solution: Check your input array to ensure it contains values. If the array is dynamically generated, add validation to ensure it's not empty before passing to the Randomize node.

Same Value Selected Repeatedly

Symptoms: The same value is selected multiple times in a row

Solution: This is normal behavior for true randomness. If you need guaranteed variety, implement additional logic to track previous selections or use a different approach like cycling through values.

Performance Issues with Large Arrays

Symptoms: Node takes longer to process with very large arrays

Solution: Consider limiting array size or pre-filtering to a smaller subset before randomization. The node processes the entire array, so extremely large datasets may impact performance.

Related Resources