Create Readable Coupon Codes or Tokens with ReadableRandom

With ReadableRandom you get readable, short and unique strings.

  • Shorter than hexdigest
  • More readable than base64
  • Totally random
  while token.blank? or User.find_by_token(token)
    self.token = ReadableRandom.get(6)
  end

Get the Readable Random Rails Plugin / Gem

Advertisements

2 thoughts on “Create Readable Coupon Codes or Tokens with ReadableRandom

  1. I suggest using ActiveSupport::SecureRandom instead of OpenSSL. It comes with rails anyways, and if I am not totally wrong it plainly wraps Ruby 1.9’s SecureRandom.

  2. Thanks for the tip, for Rails apps thats true, but it is also meant for non-rails apps, so this was no option. As far as I could see ActiveSupport::SecureRandom uses OpenSsl too (at least on 2.3.2).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s