Articles in this section
Category / Section

Using FlowMattic Variables to Generate Random Numbers

2 mins read
Updated:

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

  1. Open your workflow in FlowMattic.
  2. Add or select a step where you want to use a dynamic random number.
  3. Inside the input field, click the + icon to open the Dynamic Fields popup.
  4. The first section in the popup is FlowMattic Variables β€” search or scroll to find random_number:<NUMBER>.
  5. Select or modify the number to suit your range, e.g., random_number:1000 for values between 0 and 1000.
  6. Insert the variable β€” it will appear as {{random_number:1000}}.
  7. 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.

Zight 2025-04-13 at 1.34.40 AM.png

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Access denied
Access denied