Sha256: d900df5c3b1c8d9daf5a5db964c4bfddfb3be59a8490aefffc1c4e477cd219e2

Contents?: true

Size: 818 Bytes

Versions: 27

Compression:

Stored size: 818 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + '../../../../vendor/isaac/crypt/ISAAC.rb')

module Castronaut
  module Utilities
    class RandomString
      MagicNumber = 4_294_619_050

      def self.generate(max_length = 29)
        isaac = ::Crypt::ISAAC.new
        random_numbers = [isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber),
                          isaac.rand(MagicNumber)]

        random_string = "#{Time.now.to_i}r%X%X%X%X%X%X%X%X" % random_numbers
        random_string[0..max_length-1]
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 6 rubygems

Version Path
relevance-castronaut-0.5.4 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.6.0 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.6.1 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.7.4 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.7.5 lib/castronaut/utilities/random_string.rb
nbudin-castronaut-0.7.5 lib/castronaut/utilities/random_string.rb
factorylabs-castronaut-0.7.5 lib/castronaut/utilities/random_string.rb