Creating a random number

  • 19 August 2022
  • 0 replies
  • 205 views

Userlevel 1

Hey fellow Customer.io fans,

 

It’s not a well-known Liquid tag but Customer.io supports

{% random 100 %} // would output a number between 0 and 100

But what if you wanna have a number between 200 and 300 for instance?

{% capture random_delta %}{% random 100 %}{% endcapture %}{{random_delta | plus: 200}}

Let’s unfurl this:

  1. With the capture tag, we create a variable called `random_delta` that is a number between 0 and 100.
  2. Then we output that variable but we add a liquid filter “plus” to add 200 to the number we just created
  3. That way we have a number between 200 and 300

 

Don’t want to have to type this every time? I’d suggest looking into snippets, one of the unsung hero features IMO.


0 replies

Be the first to reply!

Reply