lib/uniqueness/generator.rb in uniqueness-0.9.0 vs lib/uniqueness/generator.rb in uniqueness-1.0.0

- old
+ new

@@ -1,14 +1,16 @@ +require 'securerandom' + module Uniqueness class << self def generate(opts = {}) options ||= {} options = uniqueness_default_options.merge(opts) dict = uniqueness_dictionary - options[:blacklist] dict -= [*(:A..:Z)].map(&:to_s) unless options[:case_sensitive] dict -= uniqueness_ambigious_dictionary if options[:type].to_sym == :human dict = uniqueness_numbers_dictionary if options[:type].to_sym == :numbers - code = Array.new(options[:length]).map { dict[rand(dict.length)] }.join + code = Array.new(options[:length]).map { dict[SecureRandom.random_number(dict.length)] }.join "#{options[:prefix]}#{code}#{options[:suffix]}" end # Dictionary used for uniqueness generation def uniqueness_dictionary