Skip to content

Instantly share code, notes, and snippets.

@bkenny
Created November 25, 2015 11:48
Show Gist options
  • Save bkenny/45813bc5c7d68dd49275 to your computer and use it in GitHub Desktop.
Save bkenny/45813bc5c7d68dd49275 to your computer and use it in GitHub Desktop.
Generate unique codes in a CSV
require 'bazaar'
require 'rails'
require "csv"
tokens_array = []
array_complete = false
while array_complete == false do
token = Bazaar.object
tokens_array << token unless tokens_array.include?(token)
puts "Added token: #{token}, number: #{tokens_array.count}"
array_complete = true if tokens_array.count == 5000
end
CSV.open("codes.csv", "wb") do |csv|
puts "Creating CSV"
tokens_array.each do |token|
csv << [token]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment