Created
May 15, 2020 10:03
-
-
Save loughlincodes/1c0ec5c0c4eec51ca894b9e7e73d1f6e to your computer and use it in GitHub Desktop.
Generate random number with Liquid (Shopify)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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