シェルの乱数の覚書
いろいろあるんだな、って思った。
$ echo $$ 25653 $ awk 'BEGIN { print PROCINFO["pid"] }' 26712 $ echo `date +%s` 1290451043 $ echo $RANDOM 28006 $ awk 'BEGIN{ srand(); print rand() }' 0.384664 $ awk 'BEGIN { srand(systime() + PROCINFO["pid"]); print rand() }' 0.270381 $ od -vAn -N4 -tu4 < /dev/urandom 177439376 $ od -An -N2 -i /dev/random 25895 $ dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" " 655519971
参考
- http://www.linuxquestions.org/questions/programming-9/shell-script-random-variable-4088/
- http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/randomvar.html
- http://journal.mycom.co.jp/articles/2010/04/30/shell-random-number/index.html
- http://awk.info/?doc/tip/random.html
- http://d.hatena.ne.jp/hycon/20101007/1286450035