Created
December 27, 2014 17:18
-
-
Save simi/d041f95d2e6a6b8ea2f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'securerandom' | |
require 'set' | |
tokens = Set.new | |
i = ENV['I'].to_i | |
length = ENV['KEY_LENGTH'].to_i | |
i.times do |i| | |
hex = SecureRandom.hex(length) | |
raise "Collision found in iteration ##{i} with key length #{length}!" if tokens.include?(hex) | |
tokens << hex | |
end | |
print "No collision for #{i} iterations with key length #{length}.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage:
I=10_000_000 KEY_LENGTH=24 ruby collision.rb