Created
October 12, 2011 09:17
-
-
Save yorzi/1280727 to your computer and use it in GitHub Desktop.
random_token.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_token(number=10) | |
Digest::SHA1.hexdigest(Time.now.to_i.to_s)[1..number] | |
end |
@namelessjon, you right, thanks! Your way is much better I think. My way relies on Time.now, but it should work correctly in my case :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're on 1.9, why not
Much reduced chance of collisions should you get two requests in one second and much less possible to predict if you know the approximate time.