# HG changeset patch # User nanaya # Date 1463390484 -32400 # Node ID ecff9d2c0500164496cfd47e073a2b7e458db3fb # Parent e9f7eeb4a0f11b93ccfc2022b34042a36b09501b Simple random string generator diff -r e9f7eeb4a0f1 -r ecff9d2c0500 bin/randstr --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/randstr Mon May 16 18:21:24 2016 +0900 @@ -0,0 +1,16 @@ +#!/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)