Created
August 12, 2014 01:24
-
-
Save yoppi/0db491b9d8dd5b60a3de to your computer and use it in GitHub Desktop.
Hash値を生成するやつ(64進数)
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
# | |
# SecureRandomでのHash値生成 | |
# | |
# 1000万回で衝突しない | |
# | |
require 'securerandom' | |
hs = {} | |
10000000.times do |i| | |
# deviseのDevise.gen_tokenから(app/models/user_magazine.rb) | |
x = SecureRandom.base64(10).tr('+/=lIO0', 'pqrsxyz') | |
if hs.key? x | |
puts "detect collision: #{x}. at #{i} time." | |
else | |
hs[x] = true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment