1、利用RANDOM取随机数

shell有一个环境变量RANDOM,范围是0-32767

如果我们想要产生0-25范围内的数:$(($RANDOM%26)) 在$(()) 是可以省略取值的$符号的。

用这个环境变量对26取模即可。

如果想得到1--68范围内的数 : $(($RANDOM%68+1))

[root@localhost ~]# echo  $(($RANDOM%68+1))
9

如果想得到6--87范围内的数 : $(($RANDOM%82+6))

[root@localhost ~]# echo  $(($RANDOM%82+6))
83

 

2、使用mkpasswd命令生产随机密码

安装:yum install expect;使用mkpasswd命令生成随机密码

  部分参数:

  -l #  (length of password, default = 10)

  -d #  (min # of digits, default = 2)

  -c #  (min # of lowercase chars, default = 2)

  -C #  (min # of uppercase chars, default = 2)

  -s #  (min # of special chars, default = 1)

  比如说需一个长度为10、至少有三个大写字母、有特殊字符的密码:mkpasswd -l 10 -C 3 -s 2

  [root@localhost ~]# mkpasswd -l 10 -C 3 -s 2

7tl2BElQ,/

。。。。。。