Sha256: 2a3a0258f5abd52f8c3fce73dac95012fca8fd962f117c14374d6fd85509f114

Contents?: true

Size: 544 Bytes

Versions: 25

Compression:

Stored size: 544 Bytes

Contents

class RandomString < String
  def initialize(length = 40)
    super(new_random_string(length))
  end


  private
  def new_random_string(length = 40)
    string = ""
    string += random_string until string.length >= length
    return string[0, length]
  end

  def random_string
    string_pairs = Digest::SHA1.hexdigest( Time.now.to_s.split(//).sort_by {rand}.join ).scan(/.{2}/)
    random_strings = string_pairs.collect{|s| s[0,1].crypt(s)}
    random_string = random_strings.join
    return random_string.gsub(/[^A-Za-z0-9]/, "")
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
qwester-0.5.0 lib/random_string.rb
qwester-0.4.0 lib/random_string.rb
qwester-0.3.5 lib/random_string.rb
qwester-0.3.4 lib/random_string.rb
qwester-0.3.3 lib/random_string.rb
qwester-0.3.2 lib/random_string.rb
qwester-0.3.1 lib/random_string.rb
qwester-0.3.0 lib/random_string.rb
qwester-0.2.2 lib/random_string.rb
qwester-0.2.1 lib/random_string.rb
qwester-0.2.0 lib/random_string.rb
qwester-0.1.4 lib/random_string.rb
qwester-0.1.3 lib/random_string.rb
qwester-0.1.2 lib/random_string.rb
qwester-0.1.1 lib/random_string.rb
qwester-0.1.0 lib/random_string.rb
qwester-0.0.9 lib/random_string.rb
qwester-0.0.8 lib/random_string.rb
qwester-0.0.7 lib/random_string.rb
qwester-0.0.6 lib/random_string.rb