News for hackers. Stuff that matters.
Re:Ruby One-Liners by cgranier on Friday September 13, 2019 @08:18PM (#20967985)
I always liked this one I wrote ages ago, to generate strong (at the time) passwords:

[code lang=“ruby”]

((33..126).map { |i| i.chr }).to_a.shuffle[0..14].join

[/code]

Re:Ruby One-Liners by petepete on Saturday September 14, 2019 @04:58AM (#20969662)
Or for readable/memorable ones

    File.readlines('/usr/share/dict/words').map(&:strip).shuffle.first(5).map(&:capitalize).join

    => "PanChloroformateParoticTillotBrushoff"
Re:Ruby One-Liners by Axsuul on Friday September 13, 2019 @08:55PM (#20968164)
A bit more efficient:

14.times.map { rand(33..126).chr }.shuffle.join

Re:Ruby One-Liners by e12e on Saturday September 14, 2019 @03:02AM (#20969357)
Why shuffle? Does it do something rand doesn't already do?

At any rate, would probably want to use https://ruby-doc.org/stdlib-2.5.1/libdoc/securerandom/rdoc/S... for password generation.

Also, I think you might just want an alphabet and use sample: https://ruby-doc.org/core-2.5.1/Array.html#method-i-sample

# unsure if you need a:

require 'securerandom'

(33..126).sample(14, random: SecureRandom).map(&:chr).join

Re:Ruby One-Liners by Axsuul on Saturday September 14, 2019 @02:19PM (#20972691)
You're right, probably doesn't need shuffle :)
Re:Ruby One-Liners by oh_sigh on Friday September 13, 2019 @09:36PM (#20968345)
And 3x more possibilities because it allows the same character more than once. But I think the last shuffle is not necessary
Re:Ruby One-Liners by cgranier on Friday September 13, 2019 @10:17PM (#20968506)
Thanks! Learned something new today (even though I’m mostly on Python now)