[Solved] Generating a string of a specific length, then filling with a value [closed]


def string_gen(length.to_i)
  chars = %w(a b c d e f g h i j k l m n o p q r s t u w x y z)
  random_string = chars.to_a[rand(chars.length)].join
  puts random_string
end

string_gen(6)
#<= "jahsyd"

If you want to do it more then one time add a .times loop:

def string_gen(length.to_i)
  chars = %w(a b c d e f g h i j k l m n o p q r s t u w x y z)
  5.times do
    random_string = chars.to_a[rand(chars.length)].join
    puts random_string
  end
end

This is completely untested.

solved Generating a string of a specific length, then filling with a value [closed]