linux系统产生随机数的方法

7年前 (2017-07-11) gtj linux, shell 0评论 已收录 697℃

方法一:
[root@sf106232 script]# echo "test$RANDOM"|md5sum|cut -c 8-21
cac37d7b700a4f
通过$RANDOM 产生随机数,然后用md5sum加密,截取需要的长度。
方法二:
[root@sf106232 script]# openssl rand -base64 15 |cut -c 6-13
3qST8gjL
这种方式产生的随机数还是很安全的。
方法三:
[root@sf106232 script]# date +%s%N
1499776288361533000
通过时间获取随机数。
方法四:
[root@sf106232 script]# head /dev/urandom|cksum
2100042156 2465
某一个时间段是唯一的。
方法五:
[root@sf106232 script]# cat /proc/sys/kernel/random/uuid
5d0cea95-9fae-4efd-a168-7b82263f00cf
[root@sf106232 script]# cat /proc/sys/kernel/random/uuid
0e65ce61-c830-4a73-9fd0-0b6c6b3d5d75
通过uuid获取随机数
方法六:
使用expect附带的mkpasswd生成随机数
yum install expect -y
[root@sf106232 script]# mkpasswd -l 9 -d 2 -c 3 -s 1
nt6a_Yc4L
参数解释:
-l 指定密码长度
-d 指定密码中数字的数量
-c 指定密码中小写字母的数量
-C 指定密码中大写字母的数量
-s 指定密码特殊字符的数量

[root@sf106232 script]# mkpasswd -l 18 -d 5 -c 5 -C 5 -s 3|md5sum
796eb6bc590898a176050718b1b0b505 -
[root@sf106232 script]# mkpasswd -l 18 -d 5 -c 5 -C 5 -s 3|md5sum |cut -c 5-10
aef6af
[root@sf106232 script]# mkpasswd -l 18 -d 5 -c 5 -C 5 -s 3|md5sum |cut -c 5-15
0d92c9f8b5b

博主

这货来去如风,什么鬼都没留下!!!

相关推荐

嗨、骚年、快来消灭0回复。

×
订阅图标按钮
Less is more!!!