Skip to content

Instantly share code, notes, and snippets.

@to4iki
Last active August 29, 2015 13:58
Show Gist options
  • Save to4iki/9947894 to your computer and use it in GitHub Desktop.
Save to4iki/9947894 to your computer and use it in GitHub Desktop.
衝突判定
CODE_LENGTH = 8
def generate_code
code = SecureRandom.hex(6).hex.to_s(36)
code = code[0, CODE_LENGTH]
code += ('A'..'Z').to_a.sample(CODE_LENGTH - code.length).join('')
code.upcase
end
def collision_detection(re_count)
ary, collisions_num = [], 0
re_count.times do
code = generate_invited_code
collisions_num += 1 if ary.include?(code)
ary << code
end
collisions_num
end
puts collision_detection(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment