shell中产生随机数的几种方法
- echo $RANDOM
[root@localhost shell]# echo $RANDOM
13603
[root@localhost shell]# echo $RANDOM
22698
[root@localhost shell]# echo $RANDOM
18368
[root@localhost shell]# echo $RANDOM
30384
[root@localhost shell]# echo $RANDOM
29354
- 使用 /dev/urandom
[root@localhost ~]# cat /dev/urandom | strings -6 | egrep "^[0-9a-zA-Z]{6}$" | head -6
lOXbnK
QgvS2y
FwJtxN
GXEfK4
nBWg4w
2b8W01
3.使用 md5sum
#!/bin/bash
for i in `seq 1 6`
do
echo "$i" |md5sum |cut -c 1-6
done