Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save loughlincodes/1c0ec5c0c4eec51ca894b9e7e73d1f6e to your computer and use it in GitHub Desktop.
Save loughlincodes/1c0ec5c0c4eec51ca894b9e7e73d1f6e to your computer and use it in GitHub Desktop.
Generate random number with Liquid (Shopify)
{% capture time_seed %}{{ 'now' | date: "%s" }}{% endcapture %}
{% assign random = time_seed | times: 1103515245 | plus: 12345 | divided_by: 65536 | modulo: 32768 | modulo: 10 %}
This will generate pseudo-random numbers beetween 0 and 9. If you need from 0 to 99, just adjust the last modulo to 100 instead of 10 (and 1000 if you need 0-999).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment