How to Generate Random Numbers in Shopify liquid
Today I am sharing a script code to create a random number in Shopify liquid.
1 2 3 4 5 | {%- assign min = 1 -%} {%- assign max = 100 -%} {%- assign diff = max | minus: min -%} {%- assign random_number = "now" | date: "%N" | modulo: diff | plus: min -%} {{ random_number }} |
And here is an example, generate a random number from 1 to 100. Wanna change the range, just edit value of min and max.
I hope it’s helpful for you.
Happy coding.