Ruby 输出长度在 8 到 16 个字符之间的每个可能的字符(A-Z、a-z、0-9)组合

Ruby Output every possible character (A-Z, a-z, 0-9) combination between 8 and 16 characters long

如何使用字符 A-Z(大写和小写)和数字 0-9 输出每个可能的字符组合(8 到 16 之间),同时还使用一些特殊字符,例如下划线和美元符号。

正如@tadman 所说,这不会在我们太阳系的生命周期内完成,但理论上,您可以这样完成:

chars = [*:A..:Z, *:a..:z, *0..9, ?$, ?_]

(8..16).each do |n|
  chars.permutation(n) do |a|
    puts a.join
  end
end

如果要在开始前计算输出行数:

(8..16).reduce(0) {|sum,n| sum + chars.permutation(n).size }

注:获取"combinations"个字符有四种Array方法:permutation, combination, repeated_permutation, and repeated_combination。您应该检查文档或对每个文档进行实验,以确保您获得正确的 "combinations."