I needed to generate a lot of unique codes, for two lists of codes, that cannot match with each other and be unique codes.
It has to be seven characters in length.

BUT I'm not satisfied with my final solution, that I had to let run all night.

* I would have liked to use a set (because sets are faster than arrays), but I couldn't split the set into two parts at the chosen index like I can with an array.
* I would have like to parallelize the tokens creation, but it would have then implied to managed the shared array of codes to check unicity, and all the lock problems involved.

Here is the code I used:

```
# n is the token length, quantity the number of tokens I want.
def gen_codes(n=7, quantity=10)
  tokens = []
  quantity.times do |q|
    token = [*('a'..'z'), *('A'..'Z'), *(0..9)].sample(7).join
    while tokens.include?(token)
      token = [*('a'..'z'), *('A'..'Z'), *(0..9)].sample(7).join
    end
    tokens << token
  end
  tokens
end

CODES1 = 750e3.to_i
CODES2 = 250e3.to_i

puts "Generating codes"

codes = gen_codes(7, CODES1+CODES2)
codes2 = codes[0, CODES2]
codes1 = codes[CODES2, CODES1]

File.open('codes1.txt', 'w+') do |f|
  f.puts codes1
end

File.open('codes2.txt', 'w+') do |f|
  f.puts codes2
end

```

Does anyone have a better solution?