M
M
Magic Code2020-06-30 17:13:44
ruby
Magic Code, 2020-06-30 17:13:44

How to set the required number of iterations?

How to set the necessary n iterations?
Here is my example:

# Функция генерирующая пароль из цифр
def passwd(n) 
  # n - количество символов пароля 
  parole = ''
  nums = Array.new(50) { |i| i * 1 }
  nums.each do |n|  # где n нужное кол-во итераций
    x = rand(nums.length)
    parole += nums[x].to_s
  end
end

p = passwd(2)
puts p  # => выдает от 1 до 50

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2020-06-30
@Panda_Code

The misunderstanding code that passwd generates should be replaced with
SecureRandom.hex(n)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question