Mike Slinn
Mike Slinn

jekyll_random_hex

Published 2020-10-03. Last modified 2023-05-18.
Time to read: 1 minutes.

This page is part of the jekyll_plugins collection, categorized under Jekyll.

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:

Gemfile
group :jekyll_plugins do 
  gem 'jekyll_random_hex'
end 

And then execute:

Shell
$ 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: 845239a5cde5.