##method 1
def random_password(size = 6)
chars = (('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0)
(1..size).collect{|a| chars[rand(chars.size)] }.join
end
puts random_password.inspect
##method 2
def newpass(len=6)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
newpass = ""
upto(len) { |i| newpass << chars[rand(chars.size-1)] }
return newpass
end
p newpass.inspect
##method 3
def generate_string(a)
new_code = random_string(6)
end
p new_code.inspect
###correct_method
##method 4
def random_string(length = 6)
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
(1..length).map {chars[rand(chars.length)]}.join
end
p random_string.inspect
##method 5
def random_string(length = 6)
rand(36**length).to_s(36)
end
p random_string.inspect
##method 6
def random_string
o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten
string = (0..50).map{ o[rand(o.length)] }.join
end
##method 7
def generate_activation_code(size = 6)
charset = %w{ 2 3 4 6 7 9 A C D E F G H J K L M N P Q R T V W X Y Z}
(0...size).map{ charset.to_a[rand(charset.size)] }.join
end
p generate_activation_code.inspect
##method 8
def generate_random_string(length=6)
string = ""
chars = ("A".."Z").to_a
length.times do
string << chars[rand(chars.length-1)]
end
string
end
p generate_random_string.inspect
##method 9
def random_alphanumeric(size=16)
chars = ('a'..'z').to_a + ('A'..'Z').to_a
(0...size).collect { chars[Kernel.rand(chars.length)] }.join
end
##method 10
def random_string
chars = ("a".."z").to_a + ("1".."15").to_a
newpass = Array.new(8, '').collect{chars[rand(chars.size)]}.join
end
p random_string.inspect
def random_password(size = 6)
chars = (('a'..'z').to_a + ('0'..'9').to_a) - %w(i o 0 1 l 0)
(1..size).collect{|a| chars[rand(chars.size)] }.join
end
puts random_password.inspect
##method 2
def newpass(len=6)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
newpass = ""
upto(len) { |i| newpass << chars[rand(chars.size-1)] }
return newpass
end
p newpass.inspect
##method 3
def generate_string(a)
new_code = random_string(6)
end
p new_code.inspect
###correct_method
##method 4
def random_string(length = 6)
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a
(1..length).map {chars[rand(chars.length)]}.join
end
p random_string.inspect
##method 5
def random_string(length = 6)
rand(36**length).to_s(36)
end
p random_string.inspect
##method 6
def random_string
o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten
string = (0..50).map{ o[rand(o.length)] }.join
end
##method 7
def generate_activation_code(size = 6)
charset = %w{ 2 3 4 6 7 9 A C D E F G H J K L M N P Q R T V W X Y Z}
(0...size).map{ charset.to_a[rand(charset.size)] }.join
end
p generate_activation_code.inspect
##method 8
def generate_random_string(length=6)
string = ""
chars = ("A".."Z").to_a
length.times do
string << chars[rand(chars.length-1)]
end
string
end
p generate_random_string.inspect
##method 9
def random_alphanumeric(size=16)
chars = ('a'..'z').to_a + ('A'..'Z').to_a
(0...size).collect { chars[Kernel.rand(chars.length)] }.join
end
##method 10
def random_string
chars = ("a".."z").to_a + ("1".."15").to_a
newpass = Array.new(8, '').collect{chars[rand(chars.size)]}.join
end
p random_string.inspect
Comments
Post a Comment