What is the best way to generate random number with liquid Shopify by avoiding caching ?
Note that “If code contains a date object, the value will be the current time of when the page was last generated from the template, not when the page is presented to a user if caching or static site generation is involved” as per the Shopify. It will return a similar number every time.
Hi @SocialAutoPost ,
Because Shopify doesn’t have a random function, if you want to randomize a number you can just rely on the date. Refer code:
{% assign min = 1 %}
{% assign max = 100 %}
{% assign diff = max | minus: min %}
{% assign randomNumber = "now" | date: "%N" | modulo: diff | plus: min %}
Hope it is clear to you.
Thank you for your reply, worked for me. @LitExtension 