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