Loading

Linux产生随机数的几种常见方法

方法1:

[root@localhost ~]# echo $RANDOM
24650

 方法二

[root@localhost ~]# openssl rand -base64 8
7X6HMer5hhY=

方法三

[root@localhost ~]# date +%s%N
1471454520014179858

方法4

[root@localhost ~]# cat /etc/passwd|cksum 
1431348031 1914

 

脚本中为了取到唯一的值,通常配合MD5结合使用:

[root@localhost ~]# echo $RANDOM$(date +%s)|md5sum|cut -c 2-10
1b2e17758

 

posted @ 2016-08-18 01:13  头痛不头痛  阅读(549)  评论(0)    收藏  举报