Skip to content

Instantly share code, notes, and snippets.

@fcalderan
Created June 25, 2014 08:05
Show Gist options
  • Save fcalderan/2098b6af9b3275ff890d to your computer and use it in GitHub Desktop.
Save fcalderan/2098b6af9b3275ff890d to your computer and use it in GitHub Desktop.
# A Liquid tag for random number generation
# Usage: {% random min:max %} where min and max are integers and min < max
module Jekyll
class Random < Liquid::Tag
def initialize(tag_name, range, tokens)
super
limits = range.split(":")
@min = limits[0].to_i
@max = limits[1].to_i
end
def render(context)
(@min + rand(@max - @min)).to_s
end
end
end
Liquid::Template.register_tag('random', Jekyll::Random)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment