Skip to content

Instantly share code, notes, and snippets.

@fcalderan
Created June 25, 2014 08:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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