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
3mix-castronaut-0.5.0.2 lib/castronaut/utilities/random_string.rb
masover-castronaut-0.4.4.4 lib/castronaut/utilities/random_string.rb
masover-castronaut-0.4.4.5 lib/castronaut/utilities/random_string.rb
masover-castronaut-0.5.0.1 lib/castronaut/utilities/random_string.rb
p8-castronaut-0.6.1.1 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.2.0 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.2.5 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.3.0 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.3.5 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.3.6 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.4.1 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.4.2 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.4.3 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.4.4 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.4.5 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.4.6 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.5.0 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.5.1 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.5.2 lib/castronaut/utilities/random_string.rb
relevance-castronaut-0.5.3 lib/castronaut/utilities/random_string.rb