Skip to content

Instantly share code, notes, and snippets.

@sklppr
Created January 28, 2014 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sklppr/8666521 to your computer and use it in GitHub Desktop.
Save sklppr/8666521 to your computer and use it in GitHub Desktop.
Coupon code generator with customizable number of parts, number of characters per part and separator.
def coupon(parts: 4, chars: 4, separator: "-")
SecureRandom.hex(parts*chars/2).upcase.scan(%r/.{#{chars}}/).join(separator)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment