Published 2020-10-03.
Last modified 2023-05-18.
Time to read: 1 minutes.
jekyll_plugins
collection.
This Liquid filter generates a random hexadecimal string of any length. Each byte displays as two characters. You can specify the number of bytes in the hex string; if you do not, 6 random bytes (12 characters) will be generated.
Installation
Add the following highlighted line to your Jekyll project's Gemfile
,
within the jekyll_plugins
group:
group :jekyll_plugins do gem 'jekyll_random_hex' end
And then execute:
$ bundle
Usage
This example generates a random hex string 6 bytes long and stores the result in a Liquid variable called id
.
Both of the following do the same thing:
{% assign id = random_hex_string %} {% assign id = random_hex_string 6 %}
The generated 6 bytes (12 characters) might be: 5dcc2dd5bfe2
.