Actions22
- Tool Actions
- Other Tool Actions
- Date Operation Actions
- Text & Formatting Actions
Tool → Generate Random Number
AI-generatedOverview
The node provides a versatile toolbox of utility operations, including the ability to generate random numbers within a specified range. The "Generate Random Number" operation allows users to create either integer or decimal random numbers between defined minimum and maximum values. This is useful in scenarios such as testing workflows with randomized data, generating unique identifiers, simulating sensor readings, or any case where controlled randomness is needed.
For example, you might use this node to:
- Generate a random discount percentage between 5 and 20.
- Create a random decimal temperature reading between -10.0 and 40.0 with two decimal places.
- Produce a random integer ID number for temporary use.
Properties
| Name | Meaning |
|---|---|
| Minimum Value | The lowest value (inclusive) that the generated random number can be. |
| Maximum Value | The highest value (inclusive for integers) that the generated random number can be. |
| Number Type | Choose whether to generate an "Integer" or a "Decimal" number. |
| Decimal Places | Number of decimal places to include if generating a decimal number (ignored for integers). |
Output
The output JSON object contains the following fields:
randomNumber: The generated random number (integer or decimal).min: The minimum value used for generation.max: The maximum value used for generation.numberType: Indicates if the number is"integer"or"decimal".range: The numeric range size calculated asmax - min + 1for integers, ormax - minfor decimals.decimalPlaces(only present ifnumberTypeis"decimal"): The number of decimal places used.
Example output for generating a decimal number:
{
"randomNumber": 23.45,
"min": 10,
"max": 50,
"numberType": "decimal",
"range": 40,
"decimalPlaces": 2
}
Example output for generating an integer:
{
"randomNumber": 17,
"min": 10,
"max": 20,
"numberType": "integer",
"range": 11
}
The node does not output binary data.
Dependencies
- No external services or API keys are required.
- The node relies on standard JavaScript Math functions for random number generation.
- No special environment variables or n8n credentials are necessary.
Troubleshooting
Error: "Minimum value must be less than maximum value"
This error occurs if the provided minimum value is greater than or equal to the maximum value. Ensure that the minimum is strictly less than the maximum.Unexpected output precision
When generating decimal numbers, the number of decimal places is controlled by the "Decimal Places" property. If the output has more or fewer decimals than expected, verify this setting.Invalid input types
Make sure that the minimum and maximum values are valid numbers. Non-numeric inputs may cause unexpected behavior or errors.
Links and References
- JavaScript Math.random() documentation
- Number.toFixed() method (used for decimal rounding)