Skip to content

Instantly share code, notes, and snippets.

@yoppi
Created August 12, 2014 01:24
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 yoppi/0db491b9d8dd5b60a3de to your computer and use it in GitHub Desktop.
Save yoppi/0db491b9d8dd5b60a3de to your computer and use it in GitHub Desktop.
Hash値を生成するやつ(64進数)
#
# 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