TOP

シェルで乱数取得(awk)

2017-12-07 17:50:37

$ awk 'BEGIN{srand('"$RANDOM"');print int(rand() * [最大値])}'
$ cat rand.sh
for i in `seq 1 30`; do
    NUM=`awk 'BEGIN{srand('"$RANDOM"');print int(rand() * 50)}'`

    echo $NUM
done

$ ./rand.sh
29
41
7
42
16
44
10
34
34
29
22
46
9
9
4
1
11
40
43
46
44
49
4
41
15
38
18
47
21
1