kqhlna
Last Updated: February 25, 2016
·
10.99K
· burke
582037f79cc8b997eed3c2e55980d474

Random URL-safe tokens with SecureRandom

You can use ruby's standard library to trivially generate random url-safe tokens.

require 'securerandom'
SecureRandom.urlsafe_base64(8)
=> "RrFeKH6k-_Y"
=> "VGARhfWcbc4"
=> "e86ga-WnMtA"
Say Thanks
Respond

2 Responses
Add your response

2122
E90b0742a0a78f583355470561d63197

any drawback or benefit to using SecureRandom.uuid?

over 1 year ago ·
2540
B9d5abee1482afbf6b987edd5e95e7b5

This is close, but not quite 100% unique. One method I've been using is to append the id of the record to the value, in order to ensure 100% unique value. The only downside is that it increases the length / gives an inconsistent link.

over 1 year ago ·