Last active
August 29, 2015 14:11
-
-
Save Malwine/e9ee90f9e030060d1ce1 to your computer and use it in GitHub Desktop.
#myfirstrubyscript
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
# | |
# #myfirstrubyscript to create 130000 unique coupon codes // June 2014 | |
# | |
codes = [] | |
RANGE = [*'0'..'9', *'A'..'Z'] | |
count = 130000 | |
def random_code | |
"CODE15-" + Array.new(5){RANGE.sample}.join | |
end | |
count.times do | |
rc = random_code | |
rc = random_code while codes.include?(rc) | |
codes << rc | |
puts rc | |
end | |
puts "Not all codes are unique" if count!= codes.uniq.size | |
File.open("codes.txt","w+") do |f| | |
codes.each {|element| f.puts(element)} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment