annotate bin/randstr @ 641:84a1e86d1afc

[vimrc] Prevent pointer to stick at the bottom of screen
author nanaya <me@nanaya.pro>
date Mon, 08 Jun 2020 15:06:56 +0900
parents ecff9d2c0500
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
586
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
1 #!/usr/bin/env ruby
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
2
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
3 require "securerandom"
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
4
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
5 def random_base62(length)
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
6 group = ["A".."Z", "a".."z", "0".."9"].map(&:to_a).flatten
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
7
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
8 length.times.map do |x|
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
9 group[SecureRandom.random_number(group.length)]
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
10 end.join
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
11 end
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
12
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
13 length = ARGV[0].to_i
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
14 length = 12 if length <= 0
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
15
ecff9d2c0500 Simple random string generator
nanaya <me@myconan.net>
parents:
diff changeset
16 puts random_base62(length)