Using FlowMattic Variables to Generate Random Numbers
FlowMattic includes a powerful built-in variable system, accessible from a dedicated admin page called βVariablesβ. This page not only lists pre-defined system variables like random_number:<NUMBER>
, but also allows users to create their own custom variables for reuse across workflows.
One of the most useful built-in variables is the random number generator, which helps you generate a dynamic number between 0
and your defined upper limit β perfect for things like OTPs, invoice IDs, or test data.
π§ How It Works
To generate a random number, you use the following syntax:
{{random_number:<NUMBER>}}
random_number:
is the variable type.<NUMBER>
defines the upper limit.- It generates a random number between
0
and<NUMBER>
(inclusive of 0, exclusive of).
β Example:
{{random_number:100}}
Will generate a number like 72
(any number between 0 and 100).
πͺ Step-by-Step: How to Use Random Number Variable
- Open your workflow in FlowMattic.
- Add or select a step where you want to use a dynamic random number.
- Inside the input field, click the
+
icon to open the Dynamic Fields popup. - The first section in the popup is FlowMattic Variables β search or scroll to find
random_number:<NUMBER>
. - Select or modify the number to suit your range, e.g.,
random_number:1000
for values between0
and1000
. - Insert the variable β it will appear as
{{random_number:1000}}
. - You can now use this variable directly β for example, in number formatting, API calls, or creating dynamic content.
π¦ Use Case Examples
1. π Generate 4-digit OTP
{{random_number:9999}}
- Used to create a random 4-digit One-Time Password.
- Example Output:
4832
2. π¦ Create a unique invoice suffix
INV-{{random_number:100000}}
- Used to create invoice codes like
INV-49832
.
3. π§ͺ Add a random delay in testing flows
{{random_number:10}}
- Used to randomly set wait times between 0 to 10 seconds for testing.
4. π Generate a short coupon code number
COUPON-{{random_number:1000}}
- Used to create short numeric codes like
COUPON-417
.
5. π§Ύ Generate customer reference number
REF{{random_number:1000000}}
- Example Output:
REF492837
π‘ Tip
You can also use this inside Format Number, Conditions, API Calls, or Custom Email Templates, just like shown in the screenshot shared below β where itβs used inside a Format Number step to apply a comma separator for readability.