annotate bin/randstr @ 696:3588f4f96c31
 
[bashrc] Add global gnu grep check
 | author | 
 nanaya <me@nanaya.pro> | 
 | date | 
 Sun, 23 Oct 2022 02:01:05 +0900 | 
 | parents | 
 ecff9d2c0500  | 
 | children | 
  | 
 | rev | 
   line source | 
  
| 
586
 | 
     1 #!/usr/bin/env ruby
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 require "securerandom"
 | 
| 
 | 
     4 
 | 
| 
 | 
     5 def random_base62(length)
 | 
| 
 | 
     6   group = ["A".."Z", "a".."z", "0".."9"].map(&:to_a).flatten
 | 
| 
 | 
     7 
 | 
| 
 | 
     8   length.times.map do |x|
 | 
| 
 | 
     9     group[SecureRandom.random_number(group.length)]
 | 
| 
 | 
    10   end.join
 | 
| 
 | 
    11 end
 | 
| 
 | 
    12 
 | 
| 
 | 
    13 length = ARGV[0].to_i
 | 
| 
 | 
    14 length = 12 if length <= 0
 | 
| 
 | 
    15 
 | 
| 
 | 
    16 puts random_base62(length)
 |