Skip to content

Instantly share code, notes, and snippets.

@oropon
Created January 23, 2014 07:51
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 oropon/8574615 to your computer and use it in GitHub Desktop.
Save oropon/8574615 to your computer and use it in GitHub Desktop.
# Const
CODE_NUMS = 100
CODE_LENGTH = 8
AVAILABLE_CHARS = ('A'..'Z').to_a.delete_if{|c| c == 'O'}
AVAILABLE_CHARS_NUM = AVAILABLE_CHARS.length
# Throw random nums to suck
code_suck = []
(CODE_NUMS*2).times do
buff = []
(CODE_LENGTH-1).times {buff << rand(AVAILABLE_CHARS_NUM)}
code_suck << buff
end
# Jangle, jangle
code_suck = code_suck
.map {|c| c << (c.inject(&:^) % AVAILABLE_CHARS_NUM) }
.map {|c| c.map{|n| AVAILABLE_CHARS[n] }.join }
.uniq
.shuffle
.take(CODE_NUMS)
puts code_suck
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment