Skip to main content

Random

Generates a random number within a specified range. Useful for creating test data, simulating user behavior, implementing delays with randomness, and adding variability to automation workflows.

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

If ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.

Input

  • Minimum Value - The minimum value of the random range (inclusive). Default is 0. Can be a constant, variable, or JavaScript expression.

  • Maximum Value - The maximum value of the random range (inclusive). Default is 100. Can be a constant, variable, or JavaScript expression.

Options

  • Round - When enabled, rounds the generated random number to the nearest integer. Default is false.
    • If disabled, the result is a decimal number with up to 2 fractional digits
    • If enabled, the result is a whole number (integer)

Output

  • Random Number - The generated random number within the specified range. Default variable name is num in Message scope.

Examples

Example 1: Random Integer Between 1 and 10

Generate a random whole number for dice simulation or selection:

// Minimum Value
1

// Maximum Value
10

// Options
Round: true

Output: Random integer like 3, 7, or 10.

Example 2: Random Decimal for Probability

Generate a random probability value between 0 and 1:

// Minimum Value
0

// Maximum Value
1

// Options
Round: false

Output: Random decimal like 0.73, 0.25, or 0.91.

Example 3: Random Wait Time

Create a random delay between 2 and 5 seconds to simulate human behavior:

// Minimum Value
2

// Maximum Value
5

// Options
Round: false

Output: Random value like 3.47 seconds. Use this with a Wait node to add natural delays.

Example 4: Random Price for Testing

Generate test data with random prices between $10 and $100:

// Minimum Value
10

// Maximum Value
100

// Options
Round: false

Output: Random price like 45.23 or 78.91.

Example 5: Random Selection from Range

Pick a random index from a collection:

// Minimum Value
0

// Maximum Value (JavaScript expression)
${msg.itemCount - 1}

// Options
Round: true

Output: Random integer index to select an item from an array.

Tips for Effective Use

  1. Humanize Automation:

    • Use random delays between actions to avoid bot detection
    • Vary mouse movements or click positions slightly
    • Randomize typing speed or interaction timing
  2. Test Data Generation:

    • Create realistic test datasets with random values
    • Generate sample prices, quantities, or scores
    • Useful for load testing or data simulation
  3. Random Selection:

    • Generate random indices to pick items from arrays
    • Remember to set Round to true for array indices
    • Example: Random between 0 and (array.length - 1)
  4. Probability and Branching:

    • Generate random number between 0 and 1
    • Use conditional nodes to create probability-based branching
    • Example: If random > 0.5, take path A, else take path B
  5. Decimal Precision:

    • Without rounding, results have up to 2 decimal places
    • With rounding, results are integers
    • The rounding uses standard mathematical rounding (0.5 rounds up)
  6. Range Validation:

    • Ensure Minimum Value is less than or equal to Maximum Value
    • Both values can be negative
    • Both values can be decimals (e.g., 0.5 to 2.5)

Common Use Cases

  • Random Delays: Add variability to wait times between actions
  • Test Data: Generate random numbers for testing workflows
  • Simulated User Behavior: Create natural variation in automation
  • Random Selection: Pick random items from lists or collections
  • Load Distribution: Randomly distribute tasks across resources
  • A/B Testing: Randomly assign test groups
  • Game Mechanics: Implement dice rolls, random events, or loot systems

Common Errors and Solutions

Error: "Minimum value is greater than maximum value"

Cause: The minimum value input is larger than the maximum value.

Solution: Ensure minimum value is less than or equal to maximum value:

// Wrong
Minimum: 100
Maximum: 10

// Correct
Minimum: 10
Maximum: 100

Error: "Min/Max value is not a number"

Cause: The input values cannot be converted to numbers.

Solution: Ensure both inputs are numeric:

// Wrong
Minimum: ${msg.min} // where min is "10" (string)

// Correct
Minimum: ${parseFloat(msg.min)}

Getting the Same Random Number

Cause: Random seed is initialized per flow, not per call.

Solution: This is expected behavior. Each call to the Random node produces a different random number. If you need reproducible results for testing, you'll need to use a fixed value instead.

Unexpected Decimal Places

Cause: Without rounding, the node returns up to 2 decimal places.

Solution:

  • Enable the Round option for integers
  • Use ToString node with formatting if you need specific decimal precision
  • Or use JavaScript to format: ${msg.num.toFixed(2)}

Random Range Doesn't Include Maximum Value

Cause: Misunderstanding of "inclusive" range.

Solution: Both minimum and maximum values are inclusive. A range of 1 to 10 can produce 1, 2, 3... 9, or 10.

Advanced Examples

Random Weighted Selection

Combine with conditional logic for weighted random selection:

// Generate random number 1-100
Minimum: 1
Maximum: 100
Round: true

// Then use Condition nodes:
// If num <= 50: Common item (50% chance)
// If num <= 80: Uncommon item (30% chance)
// If num <= 95: Rare item (15% chance)
// If num <= 100: Legendary item (5% chance)

Random Date Offset

Generate random number of days to add to current date:

// Random days between 1 and 30
Minimum: 1
Maximum: 30
Round: true

// Use with DateTime package to add random days