LoginSignup
8
7

More than 5 years have passed since last update.

bashやzshで動かすshell-scriptでランダムな数値を得るの術

Posted at

RANDOM環境変数を取ると良い感じ。

echo $RANDOM

man bashによると、0~32767の値が得られるとのこと。

Each  time this parameter is referenced, a random integer between 0 and 32767 is generated.  The sequence of random numbers may be initialized by assigning a value to RANDOM.  If RANDOM is unset, it loses its special
              properties, even if it is subsequently reset.

セキュアな用途だったらopenssl/dev/randomを使うべきですが、ちょっとしたスクリプトを書くときには便利っぽい。

8
7
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
8
7