102
91

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ランダム文字列をたくさん生成する

Last updated at Posted at 2014-04-25

[a-zA-Z0-9]{16}なランダム文字列をたくさん生成する。
シェルで実行するワンライナー

cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 32 | sort | uniq

tr -dc 'a-zA-Z0-9' 含める文字種
fold -w 16 生成する文字列の文字数
head -n 32 生成する件数

念のため、生成したい件数分出力されているか確認が必要。
ちゃんとスクリプトを書けばいいんだけど、簡単に済ませたいときはこれでいいかな。

実行結果はこんな感じ。

$ cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 8 | sort | uniq
4QrrCixUp7SH64k0
7C0jFVNj7TmFTK96
8GQeLqyfkHiFiDtu
8sLaDqQf9dNHNzDd
k0Jg6PzlbzRSQCdM
liw3Q0ALIDySM9io
qFxlNKdOPHQueD4T
rBC0EMUCisXTDobs
102
91
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
102
91

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?