view bin/randstr @ 731:4d037b0a9f41 default tip

[bashrc] Better FreeBSD compat with Windows Terminal Reference: https://github.com/microsoft/terminal/discussions/18332
author nanaya <me@nanaya.net>
date Wed, 08 Jan 2025 19:02:53 +0900
parents ecff9d2c0500
children
line wrap: on
line source

#!/usr/bin/env ruby

require "securerandom"

def random_base62(length)
  group = ["A".."Z", "a".."z", "0".."9"].map(&:to_a).flatten

  length.times.map do |x|
    group[SecureRandom.random_number(group.length)]
  end.join
end

length = ARGV[0].to_i
length = 12 if length <= 0

puts random_base62(length)